Unix Shell - Removing argument from $@ in Bourne shell

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2006 > Removing argument from $@ in Bourne shell





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Removing argument from $@ in Bourne shell
cwl

2006-03-13, 2: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

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com