Referencing the two scripts below, if you take all the command line
arguments and run them through a case statement from one script, how
can you leave the unused arguments intact for any remaining scritps to
use? I've taken a stab at this as shown below, but the best I came up
with left me escaping options which started with a minus. Is there any
way to put the unused options back in $* as they originally appeared?
Regards,
-Inet
###################### Begin server-selector.sh
#########################
#!/usr/bin/ksh
Svrs=~/scripts/servers
DoUsage(){
clear
cat << EOF
This paragraph pertains exclusively to server-selector.sh which was
sourced by the calling script: $0.
It is meant to serve as a plugin to other scripts to abstract the
process of selecting servers based on
servername, tier, or all contained in the servers file. These options:
<-t|-a|-s> will be consumed by
server-selector.sh and cannot be used by the calling script. Any other
options remain in the '$*' variable.
However those options will have any minus signs (-) escaped. If you
passed the following options to your
script: "-t dev -test1 one -test2 two", the value of the remaining
options in "$*" are: "\-test1 one \-test2 two".
EOF
}
while [ "$1" != "" ]; do
case $1 in
-t | --tier ) shift
TierFilter=$1
set -A ServerArray `egrep -e
".*\,.*\,$TierFilter" $Svrs | awk -F, '{print $1}'`
;;
-a | --all ) TierFilter='.'
set -A ServerArray `egrep -e
".*\,.*\,$TierFilter" $Svrs | awk -F, '{print $1}'`
;;
-s | --server ) shift
set -A ServerArray $1
;;
* ) Leftover="$Leftover $1"
esac
shift
done
#the only way i've found to get parameters back into $* is if they are
escaped.
#explicitly doing something like: "set -a aaa -b bbb" does not work.
Is there
#a way to put parameters back so that they are not escaped?
Leftover=`echo "$Leftover" | sed s/-/\\\\\\\-/g`
set $Leftover > /dev/null
###################### End server-selector.sh
###########################
################## Begin server-selector-example.sh
#####################
#!/usr/bin/ksh
.. server-selector.sh
while [ "$1" != "" ]; do
case $1 in
\\-x | \\-\\-xtra ) shift
x="$1"
;;
* ) DoUsage
echo "Error processing option: $1\n"
exit 1
esac
shift
done
DoStuff(){ echo "$SERVER" }
echo "Processing ${#ServerArray[@]} servers...\n"
for SERVER in ${ServerArray[@]};
do
if [[ ${#ServerArray[@]} -le 1 ]]; then
DoStuff
else
DoStuff &
fi
done
################### End server-selector-example.sh
######################
|
|
0
|
|
|
|
Reply
|
inetquestion (72)
|
3/9/2006 3:34:24 PM |
|
In article <1141918464.722989.117230@u72g2000cwu.googlegroups.com>,
"inetquestion" <inetquestion@hotmail.com> writes:
[...]
I'm not even going to attempt to untangle what you're trying to do, but
in response to the subject line:
$ print -r -- $*
$ set -- -bogus
$ print -r -- $*
-bogus
$ set --
$ print -r -- $*
$
So, yes you can set anything you want into the current args; if it begins
with a dash, you just have to give "set" a -- first to indicate the end of
options to "set" itself.
Many other commands behave this way too, although some folks always go and
write their own option parsing without implementing such a feature.
--
mailto:rlhamil@smart.net http://www.smart.net/~rlhamil
Lasik/PRK theme music:
"In the Hall of the Mountain King", from "Peer Gynt"
|
|
0
|
|
|
|
Reply
|
Richard
|
3/10/2006 12:32:56 AM
|
|
haha... I can't say I blame you for not trying to figure out all the
crap in there. However I do thank you for answering my question. That
cleared everything up!
|
|
0
|
|
|
|
Reply
|
inetquestion
|
3/10/2006 6:42:37 AM
|
|
|
2 Replies
249 Views
(page loaded in 0.068 seconds)
Similiar Articles: set command will not allow parameters with leading minus "-option ...Referencing the two scripts below, if you take all the command line arguments and run them through a case statement from one script, how can you leave... How to remove all subdirectory/file under current directory ...... command- line option "*" without an explicit "--" options delimiter, will, with empty file "-i", allow one a ... parameters, if needed, isntead of just adding `set -x ... Quick sync between two computers not connected to the internet ...With just two servers Not with standard parameters. ... is why the financial department does not allow it. ... have only Windows machines, then that option does not ... ntpd, boot time, and hot plugging - comp.protocols.time.ntp ...See the tinker command for other options. Dave Alain ... up the issue of a standard set of parameters ... and > then unconditionally set (not slew) the clock. I will allow ... Need a FORTRAN compiler for Win7 (or XP) - comp.lang.fortran ...... org/wiki/GFortranBinaries There are also other options ... the decision until "link time", which could allow the ... as if" the argument(s) were replaced by parameters with ... Weird Error Message - comp.cad.solidworksHowever, it would allow me to double-click or drag and ... them from another drive I have on the machine with negative ... I built it myself and when I did I set it up as a dual ... Courier monospace fonts and line spacing - comp.fonts... what are the interline spacing parameters that are currently set. ... If you set the leading to zero, you should get 6 ... setting default font size on command line ... getting 1 million records into excel from sas - comp.soft-sys.sas ...I've used ExcelXP tagsets that allow us to write to ... options nosource nomprint nomlogic nosymbolgen ... ExlFilename,ExlFilepath); data _null_; set &dsn ... [comp.publish.cdrom] CD-Recordable FAQ, Part 1/4 - comp.publish ...Archive-name: cdrom/cd-recordable/part1 Posting-Frequency: monthly Last-modified: 2008/10/09 Version: 2.71 Send corrections and updates to And... Neatest way to get the end pointer? - comp.lang.cIf you are indeed talking about not allowing things pointed to by parameters to ... bits in an int object are set or not set ... Then if you store a negative number in the ... set command will not allow parameters with leading minus "-option ...Referencing the two scripts below, if you take all the command line arguments and run them through a case statement from one script, how can you leave... MS-DOS set command helpType SET without parameters to display the ... if the variable name is not found in the current environment. SET command will not allow ... offset or length) is negative ... 7/24/2012 11:24:01 AM
|