bug-bash
[Top][All Lists]
Advanced

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

Re: test or [ does not handle parentheses as stated in manpage


From: Julian Gilbey
Subject: Re: test or [ does not handle parentheses as stated in manpage
Date: Tue, 6 Sep 2022 06:52:02 +0100

On Mon, Sep 05, 2022 at 06:05:04PM -0400, Greg Wooledge wrote:
> On Mon, Sep 05, 2022 at 09:55:29PM +0100, Julian Gilbey wrote:
> > if [ ("$1" = "yes" -o "$1" = "YES") -a ("$2" = "red" -o "$2" = "RED") ]
> 
> You're doing it wrong.  The parentheses have to be quoted, and separate.
> 
> [ "(" "$1" = yes" -o "$1" = YES" ")" -a ... ]
> 
> I'd strongly recommend that you DON'T do this, for two reasons:
> 
> 1) It's not compatible with the POSIX [ command.
> 
> 2) Bash offers the [[ command instead, which is a lot more powerful.
>    With [[ you can do it this way:
> 
>    [[ ( $1 = yes || $1 = YES ) && ... ]]

Oh, nice!

Thanks,

   Julian



reply via email to

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