help-bash
[Top][All Lists]
Advanced

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

Re: how much are "historic" issues with test / [ still an issue


From: Greg Wooledge
Subject: Re: how much are "historic" issues with test / [ still an issue
Date: Tue, 25 May 2021 08:44:06 -0400

On Tue, May 25, 2021 at 01:47:23PM +0200, Christoph Anton Mitterer wrote:
> I wondered how much shells (especially bash, but perhaps also dash if
> someone coincidentally knows) are still affected by this?
> 
> 1) > test "$1" -a "$2"
>    > should be written as:
>    > test "$1" && test "$2"

Bash sidesteps the issue by offering the [[ keyword instead.
The preferred way to write this in bash would be:

[[ $1 && $2 ]]


You're kind of asking the wrong questions, though.  It's not: "does dash
really have problems with this construct".  If you're writing for sh
then the question is: "will this construct work with ALL implementations
of sh in the way that I expect".  And the answer is: no, it won't.

So, don't write code that you know will have problems.  Write code that
you know will work, instead.

That's why the POSIX rationale is telling you to write using two test
commands instead of one with an ambiguous -a operator.  Using two test
commands will work, consistently and unambiguously, in all conformant
shells.



reply via email to

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