[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] xl command autocompletion: domain names

John Haxby writes ("Re: [Xen-devel] xl command autocompletion: domain names"):
> On 06/11/13 17:13, Ian Jackson wrote:
> >  bash_completion_sudo () {
> >     if [ x"`whoami`" = xroot ]; then "$@"
> >     else ${BASH_COMPLETION_SUDO-sudo} "$@"; fi
> >  }
> >  bash_completion_sudo xl list
> It's amazing how old constructs make it into new shell scripts for all
> the wrong reasons.
> For some reason there has been a resurgence in the belief that you need
> the x's _and_ the quotes.  You don't.  Ideally you'd eschew the archaic
> construct altogether.

The x's are there in case the string looks like an operator for
test(1).  Depending on the exact syntax of the expression inside [ ],
it can be ambiguous.  In this case it's OK (I think) but IMO it's a
good habit to always include the x whenever passing string data values
to test(1).

> If this particular case, however, you actually want something quite
> different:
>   if [ $(id -u) -eq 0 ] ...

I guess.  I would still write the " ".  Otherwise if id fails for some
ridiculous reason, you get a syntax error from test as well.


Xen-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.