[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test or [ does not handle parentheses as stated in manpage
From: |
Greg Wooledge |
Subject: |
Re: test or [ does not handle parentheses as stated in manpage |
Date: |
Mon, 5 Sep 2022 18:05:04 -0400 |
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 ) && ... ]]
Re: test or [ does not handle parentheses as stated in manpage,
Greg Wooledge <=
Re: test or [ does not handle parentheses as stated in manpage, Dale R. Worley, 2022/09/05