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 ]
|