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: Dale R. Worley
Subject: Re: test or [ does not handle parentheses as stated in manpage
Date: Mon, 05 Sep 2022 23:04:41 -0400

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



reply via email to

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