1758847 Members
2838 Online
108876 Solutions
New Discussion юеВ

Re: ksh and quotes

 
Rich Wright
Trusted Contributor

Re: ksh and quotes

What about this code?
abc script
#!/bin/sh
set -x
args=''
num_args=$#
i=1
while [ $i -le $num_args ]
do
arg=`eval echo \\$"$i"`
if $(echo $arg | grep -q ' ');then
args=$args"'$arg' "
else
args=$args"$arg "
fi
i=`expr $i + 1`
done
echo $args
--end of script--
--test run--
# ./abc -s 'a b c'
+ args=
+ num_args=2
+ i=1
+ [ 1 -le 2 ]
+ + eval echo $1
+ echo -s
arg=-s
+ echo -s
+ grep -q
+ args=-s
+ + expr 1 + 1
i=2
+ [ 2 -le 2 ]
+ + eval echo $2
+ echo a b c
arg=a b c
+ grep -q
+ echo a b c
+ args=-s 'a b c'
+ + expr 2 + 1
i=3
+ [ 3 -le 2 ]
+ echo -s 'a b c'
-s 'a b c'
---end of test---

Rich
eric stewart_2
Advisor

Re: ksh and quotes

Rich
here is what I got from the script:
[ 5 -le 4 ]
+ /cts/sas612/sas -work /prd/works2 -autoexec /prd/preclinical/pbsyst/ahtest/ahtest.sas -initcmd 'af c=ahtest.ahtest.menu.program'

ERROR: Cannot find batch input file '/prd/home/estewar1/c=ahtest.ahtest.menu.program''.


I just do not see where or why there are 2 quotes
Used your script. It seems to do what I want.
Any other ideas?
eric stewart_2
Advisor

Re: ksh and quotes

Thanks to all,
Sometimes simple eludes us.
In this particular case the parameter that I had to pass (stumbled on it) could be separated by spaces or commas.
I just added the comma between the af and the file name and it does not matter about the quotes.
I will try to award points Friday.
Thanks again.
eric stewart_2
Advisor

Re: ksh and quotes

assigned points as promised