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 10:20:33 +0100

On Mon, Sep 05, 2022 at 11:04:41PM -0400, Dale R. Worley wrote:
> Julian Gilbey <jdg@debian.org> writes:
> > Upgrading to bash 5.2.0(1)-rc2 did not help, neither did using \(
> > instead of (, and neither did putting spaces around the parentheses.
> 
> It's ugly.  The first point is that ( and ) are special characters and
> if unquoted are isolated tokens that have special syntax.  So in order
> to get [ to see them as arguments, you have to quote ( and ).  But the
> quoted characters are ordinary characters and to make them be separate
> arguments to [, you have to separate them from the adjacent arguments
> with spaces.  So this version works:
> 
>     if [ \( "$1" = "yes" -o "$1" = "YES" \) -a \( "$2" = "red" -o "$2" = 
> "RED" \) ]
>     then
>         echo "Yes, it's red"
>     else
>         echo "No, it's not red"
>     fi
> 
> Dale

Thanks Dale!

I agree that it's ugly :)

Best wishes,

   Julian



reply via email to

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