Re: assign a string variable onto itself with concat ksh
- From: "theshowmecanuck" <theshowmecanuck@xxxxxxxxx>
- Date: 28 Sep 2006 12:58:28 -0700
I am trying to weed out mutually exclusive command line options by
concatenating them into a string. I want to check this string to see
if a mutually exclusive option was also entered on the command line. I
have included a code example of what I am trying to do below.
So (referring to the code snippet below), if options 'r' and 'o' are
mutually exclusive and if the user enters this on the code line:
myScript -r 1234 -o 4321
In the 'r' part of the case statement optString should equal "r" where
it then greps the optString for the presence of "o" which it does not
find.
Then in the 'o' part of the case statement optString should equal "ro"
(concatenated) where it then greps the optString for the presence of
"r" which it *does* find. It then prints an error message and exits
normally (expected behaviour).
Or is there an easier way to check for mutually exclusive options?
....
typeset -L optString
....
while getopts o:r:h PARAM
do
case ${PARAM} in
h) usage
exit 0
;;
o) print "'-o' option" # for debugging
parameter=${OPTARG}
optString="$optString$PARAM"
print "optionString in o is $optString" # output = "r" when I would
expect "ro"
$tempString="$optString$PARAM"
print "tempString in o is $tempString" # output = "ro"
like what I want to see in optString
if (( $(echo $optString | egrep -c r) > 0 )); then
print "ERROR: -o option is mutually exclusive with -r option."
usage
exit 0
fi
;;
r) print "'-r' option" # for debugging
parameter=${OPTARG}
optString="$optString$PARAM"
print "optString in r is $optString" # for debugging
if (( $(echo $optString | egrep -c o) > 0 )); then
print "ERROR: -r option is mutually exclusive with -o option."
usage
exit 0
fi
;;
?) usage
exit 0
;;
esac
done
....
Bruce Barnett wrote:
"theshowmecanuck" <theshowmecanuck@xxxxxxxxx> writes:
optString="$optString$newString"
As you might guess (or know outright! :-) my idea doesn't work.
Show us yout script. This should work, as long as you don't change it
in a subshell.
--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
.
- Follow-Ups:
- Re: assign a string variable onto itself with concat ksh
- From: Glenn Jackman
- Re: assign a string variable onto itself with concat ksh
- References:
- assign a string variable onto itself with concat ksh
- From: theshowmecanuck
- Re: assign a string variable onto itself with concat ksh
- From: Bruce Barnett
- assign a string variable onto itself with concat ksh
- Prev by Date: From a bash array to a csv file line?
- Next by Date: Re: using sed to retrieve the hour in a timestamp
- Previous by thread: Re: assign a string variable onto itself with concat ksh
- Next by thread: Re: assign a string variable onto itself with concat ksh
- Index(es):
Relevant Pages
|