choice of control operators in scripts

Paul Fox pgf at brightstareng.com
Mon May 12 20:02:22 PDT 2008


denys wrote:
 > 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!

i'm sure there have been lots of bugs, in lots of shells.  but if
you start by assuming your shell is buggy, then you might as well
give up.  there is no point in writing scripts to cater to such
use.  who knows what other bugs there might be?

 > 
 > > 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.

yes, what i wrote was incorrect.  this was covered earlier. 
thanks.

paul
=---------------------
 paul fox, pgf at brightstareng.com


More information about the busybox mailing list