Hey Gents,
When trying to pass a variable of paramters to another script, to reduce
amount of code:
OPT1="This is my Option";
OPT2="/folder/file";
PARMS="-u \"me\" -J \"$OPT1\" -g \"$OPT2\"";
then passing it in like this:
./script.ksh -n 1 "$PARMS";
I get this:
UARG=| "me" -J "This is my Option" -g "/folder/file"|
Or I get this:
UARG=|"me"|
when I try to pass it in this manner:
./script.ksh -n 2 ${PARMS};
Looks like it manages to grab a part of what's in $PARMS but not the
rest of the string. Was curious about this behaviour and if KSH had any
way to make this work? Full code is below. Tried a couple of
variations including ' but no luck. This is an older KSH93 version. I
don't have the option of changing this version unfortunately.
Cheers, Tom
---------------------------------------------------------
# cat main.ksh
#!/usr/bin/ksh93
OPT1="This is my Option";
OPT2="/folder/file";
PARMS="-u \"me\" -J \"$OPT1\" -g \"$OPT2\"";
./script.ksh -n 0 -u me -J "$OPT1" -g "$OPT2";
./script.ksh -n 1 "$PARMS";
./script.ksh -n 2 ${PARMS};
./script.ksh -n 3 "${PARMS}";
./script.ksh -n 4 $PARMS;
# cat script.ksh
#!/usr/bin/ksh93
while getopts n:u:g:J: option; do
case ${option} in
n) NARG="$OPTARG"
;;
u) UARG="$OPTARG"
;;
g) GARG="$OPTARG"
;;
J) JARG="$OPTARG"
;;
[?]) print >&2 "Good Luck!";
exit 1
;;
esac
done
print "NARG=|$NARG|";
print "UARG=|$UARG|";
print "GARG=|$GARG|";
print "JARG=|$JARG|";
print;
# ./main.ksh
NARG=|0|
UARG=|me|
GARG=|/folder/file|
JARG=|This is my Option|
NARG=|1|
UARG=| "me" -J "This is my Option" -g "/folder/file"|
GARG=||
JARG=||
NARG=|2|
UARG=|"me"|
GARG=||
JARG=|"This|
NARG=|3|
UARG=| "me" -J "This is my Option" -g "/folder/file"|
GARG=||
JARG=||
NARG=|4|
UARG=|"me"|
GARG=||
JARG=|"This|
# echo ${.sh.version}
Version M 93t+ 2009-05-01
#
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users