[Top][All Lists]

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

test or [ does not handle parentheses as stated in manpage

From: Julian Gilbey
Subject: test or [ does not handle parentheses as stated in manpage
Date: Mon, 05 Sep 2022 21:55:29 +0100

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat 
-Werror=format-security -Wall 
uname output: Linux erdos 5.18.0-4-amd64 #1 SMP PREEMPT_DYNAMIC Debian 
5.18.16-1 (2022-08-10) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release


According to the bash manpage, the test builtin should accept

       ( expr )
              Returns the value of expr.  This may be used to  override
              the normal precedence of operators.

But the following small script, saved as/tmp/testtest.sh:


if [ ("$1" = "yes" -o "$1" = "YES") -a ("$2" = "red" -o "$2" = "RED") ]
    echo "Yes, it's red"
    echo "No, it's not red"

fails when called:

$ /tmp/testtest.sh yes red
tmp/testtest.sh: line 3: syntax error near unexpected token `"$1"'
/tmp/testtest.sh: line 3: `if [ ("$1" = "yes" -o "$1" = "YES") -a ("$2" = "red" 
-o "$2" = "RED") ]'

Upgrading to bash 5.2.0(1)-rc2 did not help, neither did using \(
instead of (, and neither did putting spaces around the parentheses.

I have also checked (using strace) that it was using the builtin [
rather than /usr/bin/[.

Best wishes,


reply via email to

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