[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test && test --> test -a
From: |
Tim Van Holder |
Subject: |
Re: test && test --> test -a |
Date: |
Wed, 5 Dec 2001 10:32:34 +0100 |
> For what it's worth, autoconf says the following. (Oh, but is this
> saying POSIX doesn't specify -a and -o at all, or only that it doesn't
> specify their precedence?)
Draft 6 of the new POSIX standard lists -a, -o and parens as XSI
extensions. It also has this to say:
Scripts should be careful when dealing with user-supplied input that
could be confused with primaries and operators. Unless the application
writer 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.
That is, in cases where maximal portability is of concern, replace:
test expr1 −a expr2
with:
test expr1 && test expr2
and replace:
test expr1 −o expr2
with:
test expr1 || test expr2
but note that, in test, −a has higher precedence than −o while "&&" and "||"
have equal
precedence in the shell.
Parentheses or braces can be used in the shell command language to effect
grouping.
Parentheses must be escaped when using sh; for example:
test \( expr1 −a expr2 \) −o expr3
This command is not always portable outside XSI-conformant systems. The
following form can
be used instead:
( test expr1 && test expr2 ) || test expr3
Re: test && test --> test -a, Gary V. Vaughan, 2001/12/04