bug-bash
[Top][All Lists]
Advanced

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

Re: Strange Problem with 'test' or '['


From: Greg Wooledge
Subject: Re: Strange Problem with 'test' or '['
Date: Wed, 23 Dec 2015 09:09:01 -0500
User-agent: Mutt/1.4.2.3i

On Wed, Dec 23, 2015 at 11:26:51AM +0100, Bytec GmbH - Helmut Koeberle wrote:
> Here is my simple bash script 'tst' that checks wether the first char of
> an argument is a slash.

It can be written in a much simpler way:

[[ $arg = /* ]]

Or:

case $arg in /*) ...

This part actually does look like a bug, though:

> if [ "true" = "true" -a "${h:0:1}" = "/" ]; then echo slash; fi

I can reproduce it (in 4.4.0-beta):

imadev:~$ h='(nopath)'
imadev:~$ [ true = true -a "${h:0:1}" = / ]
bash: [: `)' expected, found /

That said, one SHOULD NOT use -a in a test or [ command.  It's not
supported by POSIX any more.  If you want compound tests with test/[
you need to use multiple commands:

imadev:~$ [ true = true ] && [ "${h:0:1}" = / ]
imadev:~$ 

Support for the legacy -a argument is a bash extension.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]