From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Haxby Subject: Re: xl command autocompletion: domain names Date: Thu, 07 Nov 2013 10:02:15 +0000 Message-ID: <527B6527.4010204@oracle.com> References: <21102.35201.728312.130566@mariner.uk.xensource.com> <1383231830.25018.100.camel@dagon.hellion.org.uk> <21113.4284.248761.181909@mariner.uk.xensource.com> <1383732230.26213.34.camel@kazak.uk.xensource.com> <1383736560.26213.69.camel@kazak.uk.xensource.com> <21114.30900.637020.288865@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21114.30900.637020.288865@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson , Matthew Daley Cc: Ian Campbell , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org 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