scripts
Uwe Kleine-König
u.kleine-koenig at pengutronix.de
Wed Mar 2 11:14:19 EST 2011
On Tue, Mar 01, 2011 at 04:20:25PM +0200, Baruch Siach wrote:
> Hi Marc,
>
> On Tue, Mar 01, 2011 at 03:11:31PM +0100, Marc Kleine-Budde wrote:
> > On 03/01/2011 03:06 PM, Vanalme Filip wrote:
> > [...]
> >
> > > One more question about barebox scripts (I guess even scripts in
> > > general...). This is part of a script from another board (that I took
> > > over for my own board):
> >
> > > #!/bin/sh
> > >
> > > . /env/config
> > >
> > > If [ x$1 = xflash ]; then
> > > root=flash
> > > kernel=flash
> > > fi
> > >
> > > if [ x$1 = xnet ]; then
> > > root=net
> > > kernel=net
> > > fi
> > >
> > > why the scripts are using i.e. [ x$1 = xflash ] instead of just simply [ $1 = flash ] ? Both are doing the same, no ?
> >
> > The shell is quite old and doesn't support that. But you're right for
> > modern shells like bash or dash.
>
> I get this under bash:
>
> $ [ $UNDEF = test ]
> bash: [: =: unary operator expected
>
> However '[ "$UNDEF" = test ]' behaves as expected under bash (but not under
> hush, which is the shell of Barebox).
I didn't test it, but even if a variable is defined, I guess this might
result in trouble:
arg=-n
[ $arg = flash ]
(At least I remember this being the reason for using "x$arg" back when I
worked on Solaris.)
And note without quoting quite interesting things can happen, e.g.:
test -n $arg
returns false if arg="= 42".
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
More information about the barebox
mailing list