1758863 Members
3062 Online
108876 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...