[EMAIL PROTECTED] wrote:
>       foo=
>       [ -n ${foo} ] && echo true
>
>       Prints "true".

That's the correct behavior.

>       Should probably print an error, since after the command is
>       expanded there are only three arguments, so the final ] should
>       be interpreted as the argument to -n, thus leaving the command
>       with a missing ] terminator.

No, the final ] is always taken to be the match for [.  Anything in
between has to be parsed consistently with that.  In this case, it
means that the test expression includes only one argument, "-n".
Since there is only one, it is taken to be an operand, even if it
happens to have the same spelling as an operator.  The operand is
tested for being nonempty, which "-n" is, so the result here is true.

To avoid pitfalls like this, always quote variable expansions.  The [[
command is also less tricky.


paul


Reply via email to