Subject: Re: (s)hell quoting (s)hell
To: Schwerzmann, Stephan <stephan.schwerzmann@schmid-telecom.ch>
From: David Laight <david@l8s.co.uk>
List: netbsd-users
Date: 03/03/2006 19:18:46
On Wed, Mar 01, 2006 at 12:15:11PM +0100, Schwerzmann, Stephan wrote:
>
> troubles start with specific option --optP aimed at 'neutralizing'
> an environment variable; that is make tool work as if the env.var would
> not be set but without messing with the env.var itself.
>
> reading from the doco, it tells to use --optP "" (2x doublequotes)
>
> interactive invocations of tool --optP "" are successful
>
> to bring doublequotes into the factored out string, I change the
> assignment to use single quotes (no evaluations needed in there)
Ah, the real problem you have is that you don't want quotes, what you
are trying to generate is a zero length argument string.
> TOOL='tool --optA --optB --optP "" '
> ${TOOL} --optX | ...
So the above generates an argument that is "" (not what you want).
When ${TOOL} is split into tokens (using the separators in $IFS) adjacent
IFS whitespace is treated as a single separator, so cannot be used to
generate an empty argument. If you add a non-whitespace character to IFS
you can generate empty arguments, however you are likely to find that the
shells are buggy in this area. However, as an example:
$ IFS=' :'
$ x='a b:c::d'
$ set -- $x
$ echo $#
5
$ echo x${3}y
xcy
$ echo x${4}y
xy
$ echo x${5}y
xdy
However you are probably better of escaping all the other $, " and ' in the
line and using:
$ eval ${TOOL} ...
David
--
David Laight: david@l8s.co.uk