set command ignoring single/double quotes

set command ignoring single/double quotes

Post by inetquestio » Thu, 29 Jun 2006 00:45:17



I'm trying compose the value of "$command" as my script runs so that
the value of $* can be set at the end.  However this method as shown in
the last example seems to ignore single or double quotes and ends up
giving me 7 parameters instead of 5.  Anyone have a suggestion on how
to correct this?

Regards,

-Inet

-------------------------------------
set -- -a aaa -b "b1; b2; b3" -c
echo $*
-a aaa -b b1; b2; b3 -c

echo $#
5
-------------------------------------
set -- -a aaa -b 'b1; b2; b3' -c
echo $*
-a aaa -b b1; b2; b3 -c

echo $#
5
-------------------------------------
commands="-a aaa -b 'b1; b2; b3' -c"
set -- $commands
echo $*
-a aaa -b 'b1; b2; b3' -c

echo $#
7
-------------------------------------

 
 
 

set command ignoring single/double quotes

Post by inetquestio » Thu, 29 Jun 2006 01:48:29


This fixed it...

commands="-a aaa -b 'b1; b2; b3' -c"
eval set -- $commands
echo $*
echo $#
5

 
 
 

set command ignoring single/double quotes

Post by Andrew Gabri » Thu, 29 Jun 2006 02:17:44




Quote:> I'm trying compose the value of "$command" as my script runs so that
> the value of $* can be set at the end.  However this method as shown in
> the last example seems to ignore single or double quotes and ends up
> giving me 7 parameters instead of 5.  Anyone have a suggestion on how
> to correct this?


command, but the "b1; b2; b3" will be passed in as a single argument,
not three arguments.

e.g. using my_echo which echos each argument on a new line...

$ my_echo()

Quote:> {
> while [ $# -gt 0 ]; do
> echo $1
> shift
> done
> }

$ set -- -a aaa -b "b1; b2; b3" -c

-a
aaa
-b
b1; b2; b3
-c
$

--
Andrew Gabriel

 
 
 

set command ignoring single/double quotes

Post by inetquestio » Thu, 29 Jun 2006 02:41:07


Andrew thans for the feedback.  However using $* in your code would
produce the same result.  The outcome is no different than the first
two examples I posted which also show a result of 5 items in the list.