Why "never use the
-a
or-o
operator"?
Porque eles podem ser ambíguos e, portanto, não são compatíveis com POSIX :
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"
How can I do "use several
[
commands and the&&
and||
shell operators)"?
Fazendo vários testes e encadeando-os usando esses operadores; por exemplo:
[ 0 -eq 0 -a \( 0 -eq 1 -o 1 -eq 1 \) ]
poderia ser reescrito como o equivalente:
[ 0 -eq 0 ] && ([ 0 -eq 1 ] || [ 1 -eq 1 ])
ou melhor:
[ 0 -eq 0 ] && { [ 0 -eq 1 ] || [ 1 -eq 1 ]; }