cc: [email protected]
Subject: Re: Re: [ast-users] [ksh93] How to understand `[ -n hello world ]'?
--------
> I know what this means. I've been using bash for years and I know
> what's the difference between [ ] and [[ ]].
> I just cannot understand how to interpret [ -n foo bar ] in ksh. ksh
> is a laguage, though it's not as powerful as other languages like
> perl. But ksh has its own syntax. Don't tell users the behavior of [
> -n foo bar ] is undefined. If it's undefined, just give me a syntax
> error message. But [ -n foo bar ] does mean something because ksh
> thinks it's TRUE.
>
>
It isn't a syntax error since [...] and test are not part of the shell
grammar but are separate utilities which may be built-in.
For exampe, how can the shell determine whether
[ "$@" ]
is a syntax error or not?
What I could do is modify the test and [...] utilities to display
an error for every undefined case. However, I suspect that if I
do this, I will break some script that allowed this combination in
some version of test.
It isn't even clear what message should be given. It the problem
that foo is not a operator, or is the problem that there is an
extra argument?
It is possible that construct cases that have multiple interpretations.
[[...]] on the other hand is part of the shell grammar. The operators
have to be recognized when parsing the script. Since word splitting
and file expansion are not done on arguments, the shell can tell how
many arguments there are. Instead of -a and -o which can be confused
as operands, [[...]] uses && and || which is part of the grammar.
Other shells have picked up [[...]] so therefore I recommend that
you abandon test and [...] and use [[...]] instead.
[[...]] was in ksh88 so it will have been around for nearly 25 years.
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users