choice of control operators in scripts
Denys Vlasenko
vda.linux at googlemail.com
Tue May 13 00:50:17 UTC 2008
On Monday 12 May 2008 23:06, Paul Fox wrote:
> > > If you fell paranoid today (highly recommended),
> > > add x"" to guard against less than ideal implementations of []
> > > which can be confused by e.g. foo=-n :
> > >
> > > [ x"$foo" = x"bar" ]
> >
> > I have no experience of shells that are _so_ buggy. Do you mean this:
> >
> > [ x-n = xbar ]
> >
> > might confuse any non-buggy shell?
>
> no. he means that this:
> [ "-n" = "bar" ]
>
> might confuse a shell that interprets it as:
> [ -n = bar ]
>
> i've never seen such a shell. i think adding the 'x' "just in
> case" is very ugly.
It's not "just in case". There are shells and [ programs
which are known to be buggy. Hell, not so long ago bbox's
one was fixed for a similar bug!
> just putting the args to test in double
> quotes has always been enough for me.
Double quotes are removed before parameters are passed to the executable
(or shell builtin), and as such they cannot matter.
[ -n = bar ] works because [ has code
which decides that if you have 3 args, it must be "val1 op val2". etc.
Look into test.c in bbox tree.
--
vda
More information about the busybox
mailing list