All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Haxby <john.haxby@oracle.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Matthew Daley <mattjd@gmail.com>
Cc: Ian Campbell <Ian.Campbell@citrix.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: xl command autocompletion: domain names
Date: Thu, 07 Nov 2013 10:02:15 +0000	[thread overview]
Message-ID: <527B6527.4010204@oracle.com> (raw)
In-Reply-To: <21114.30900.637020.288865@mariner.uk.xensource.com>

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.

A long time ago, maybe around Unix Edition 7, maybe before, it was
common to see

  [ x$foo = x ]

to test for an empty "$foo".   Note the lack of quotes.   If $foo is
indeed empty then this expanded to [ x = x ] (obviously).  Without the
x's you would get [ = "" ] which is equally obviously a syntax error.

At some stage, decades ago, [ "$foo" = "" ] became possible and the old
syntax which had a naked $foo became obsolete.

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.

If this particular case, however, you actually want something quite
different:

  if [ $(id -u) -eq 0 ] ...

:)

jch

  parent reply	other threads:[~2013-11-07 10:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-27 22:55 xl command autocompletion: domain names Matthew Daley
2013-10-28 15:57 ` Ian Jackson
2013-10-28 22:29   ` Matthew Daley
2013-10-31 15:03     ` Ian Campbell
2013-10-31 15:22       ` Ian Jackson
2013-11-05  8:11         ` Matthew Daley
2013-11-05  8:10       ` Matthew Daley
2013-11-05 10:09         ` Ian Campbell
2013-11-05 15:37         ` Ian Jackson
2013-11-06  0:18           ` Matthew Daley
2013-11-06 10:03             ` Ian Campbell
2013-11-06 11:14               ` Matthew Daley
2013-11-06 11:16                 ` Ian Campbell
2013-11-06 11:40                   ` Matthew Daley
2013-11-06 17:13                     ` Ian Jackson
2013-11-07  1:10                       ` Tim Deegan
2013-11-07 10:02                       ` John Haxby [this message]
2013-11-08 15:11                         ` Ian Jackson
2013-11-20 14:06                           ` John Haxby
2013-11-21 18:56                             ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=527B6527.4010204@oracle.com \
    --to=john.haxby@oracle.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=mattjd@gmail.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.