Removing argument from $@ in Bourne shell
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Removing argument from $@ in Bourne shell




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Removing argument from $@ in Bourne shell  
cwl


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-13-06 07:48 AM

Here's some Bourne shell code I developed that removes designated
options from $@ and moves them to the beginning of the argument list,
leaving the other arguments as-is (except shifted to the right). Feel
free to post if you know of a better, shorter, cleaner, generic way to
do it in Bourne shell without eradicating white space, etc., in the
other arguments. Thanks.

#!/bin/sh
# moveopts - Bourne shell program to move specified input
#    options, if supplied by user, to beginning of argument
#    list.  Options to be moved to beginning of argument
#    list cannot contain white space, but all other
#    arguments can contain white space.
# Usage:  moveopts [arguments] [-ee] [-ajj]
# Created:  2006-03-12, cwl, comp.unix.shell.
# Revised:  2006-03-13, cwl, comp.unix.shell.

clear="shift $#"
for arg do
$clear;clear=
case $arg in
-ee) opts="$opts $arg";;  # Move this option to beginning of
list.
-ajj) opts="$opts $arg";; # Move this option to beginning of
list.
*) set -- "$@" "$arg";;
esac
done
set -- $opts "$@"

# Print new, rearranged argument list.
for arg in "$@";do printf "\"$arg\" ";done;printf "\n"
exit 0






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:19 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register