scripting problem

Darrin Chandler dwchandler at stilyagin.com
Fri Feb 16 14:54:02 MST 2007


On Fri, Feb 16, 2007 at 02:41:38PM -0700, Eric Shubes wrote:
> I wasn't quite clear enough I guess. Since I'm building a variable number of
> parameters, I can't specify each one separately, and thus cannot use quotes
> when invoking the command.
> 
> Using your example, I need to do:
> argument="this is"
> scriptname.sh $argument a parm
> and have it come out the same as your example. I can't put the whole thing
> in quotes because I have a list of arguments, some containing spaces and
> some not.

This can get a little tricky because interpretation can (and does)
happen at any of several levels. Then, there are different methods of
quoting.

echo "foo bar"
echo 'foo bar'
echo foo\ bar

Many times the "\ " quoting is easiest to propagate down levels. So that
when you really want "foo\ bar" you end up using "foo\\ bar" because the
first interpretation evals and removes the escape you end up with a bare
space, which the next evaluation uses to separate args. With the double
backslash the first eval turns it into a single "\" and the second eval
will correctly see the escaped space "\ " and pass that through. Am I
making sense?

-- 
Darrin Chandler                   |  Phoenix BSD Users Group
dwchandler at stilyagin.com          |  http://bsd.phoenix.az.us/
http://www.stilyagin.com/darrin/  |


More information about the PLUG-discuss mailing list