[Top][All Lists]

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

Re: "The `-a', `-o', `(', and `)' operands are not portable": please cl

From: Eric Blake
Subject: Re: "The `-a', `-o', `(', and `)' operands are not portable": please clarify
Date: Tue, 4 Aug 2009 21:42:43 +0000 (UTC)

> What I'd like therefore is a rationale: if -a, -o and parentheses are
> not in POSIX 1990, please say so

They are only listed as XSI extensions in older POSIX.  Not all
shells implemented XSI extensions (think of debian's posh), and
even among those that did, the choices for order of precedence
when there are more than four operands is ambiguous in the
standard, and thus inconsistent between implementations.

The definitive nail in the coffin on using these is POSIX 2008:


which states, in no uncertain terms,

The XSI extensions specifying the -a and -o binary primaries and the '(' and 
')' operators have been marked obsolescent. (Many expressions using them are 
ambiguously defined by the grammar depending on the specific expressions being 
evaluated.) Scripts using these expressions should be converted to the forms 
given below. Even though many implementations will continue to support these 
obsolescent forms, scripts should be extremely careful when dealing with 
user-supplied input that could be confused with these and other primaries and 
operators. Unless the application developer knows all the cases that produce 
input to the script, invocations like:

test "$1" -a "$2"

should be written as:

test "$1" && test "$2"

to avoid problems if a user supplied values such as $1 set to '!' and $2 set to 
the null string.

Eric Blake

reply via email to

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