1849787 Members
2954 Online
104044 Solutions
New Discussion

ksh and quotes

 
eric stewart_2
Advisor

ksh and quotes

I have a shell script that usualy appends the passed parameters from the command line onto the real command.
The problem I have is passing the quotes.
Here is the command line abc -s 'a b c'
here is abc:
sas $*

What get run is sas -s a b c

AFter I post I will try to look at past items but I know someone with real knowledge will point me to the solution faster than I can find it.
TIA

13 REPLIES 13
Ian Kidd_1
Trusted Contributor

Re: ksh and quotes

Try passing "'a b c'".
If at first you don't succeed, go to the ITRC
H.Merijn Brand (procura
Honored Contributor

Re: ksh and quotes

From 'man sh-bourne" :

A character can be quoted (i.e., made to stand for itself) by
preceding it with a \. The pair \new-line is ignored. All characters
enclosed between a pair of single quote marks (''), except a single
quote, are quoted. Inside double quote marks (""), parameter and
command substitution occurs and \ quotes the characters \, `, ", and
$. "$*" is equivalent to "$1 $2 ...", whereas "$@" is equivalent to
"$1""$2" ....

Would that help? Sometimes $* is better, sometimes $@
Enjoy, Have FUN! H.Merijn
eric stewart_2
Advisor

Re: ksh and quotes

ian
Still NG.
I even tries abc '''a b c'''
and that does not work.

Any ksh option that says to pass the whole parameter string as one parameter and do not touch the quotes?
Leif Halvarsson_2
Honored Contributor

Re: ksh and quotes

Hi

I am not sure I have understand this correct but perhaps this work for you:

abc -s \`1 2 3\`
Rodney Hills
Honored Contributor

Re: ksh and quotes

If in script abc you did
echo :$1:

you would see-
:a b c:

This is because those three letters make up parameter #1. If you wish to quote them again to sas, then use-
sas -s "$@"

This will again pass the three letters as one argument to the shell.

Hope this helps...

-- Rod Hills
There be dragons...
eric stewart_2
Advisor

Re: ksh and quotes

procura
Is there any way to tell if the parameters or command line has the quotes in it so I can use $@ in one case and $* in the other?
eric stewart_2
Advisor

Re: ksh and quotes

Rodney,
This worked for the quoted string but then I tried it where there was no quoted string to pass and then the normal command did not work.
Thats what promted the oither reply.
Thanks
Ian Kidd_1
Trusted Contributor

Re: ksh and quotes

Try modifying the script so that:

TEST=\'$*\'

sas $TEST
If at first you don't succeed, go to the ITRC
Rodney Hills
Honored Contributor

Re: ksh and quotes

I think Ian's solution would pass the argument with the single quotes as part of the argument.

If sas is expecting to see the single quotes, then Ian's example is ok.

If sas is not expecting to see the single quotes, ie the three letters are just the first argument, then you will have to do the following-

eval sas $TEST

But I think this is becoming overkill. Maybe a little more info on what you really are trying to do.

my 2 cents...

-- Rod Hills
There be dragons...
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