cc: [email protected]
Subject: Re: Re: Re: [ast-users] [ksh93] How to understand `[ -n hello world ]'?
--------
>
>> 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.
>>
I just went back to some earlier notes and now I understand why
the shell does not report an error for [ -n foo bar ].
My goal with [...] was to avoid breaking existing scripts and my
expectations where that new scripts would use [[...]] in which
case the shell could do checking at compile time so that ksh -n
would detect most errors.
However, in old version of test, if a user did
test -f foo*
and there were files foo and foobar, the shell would expand this to
test -f foo foobar
and the bourne shell would give 0. The standard does not require
this behavior, but if I treated this as an error, it would break
some existing scripts.
Thus, I assumed that
test -letter foo ...
which is unspecified when ... is not -a or -o in the standard should
be treated as
test -letter foo
There is no reliable way to report errors and preserve backward
compatibility. The only reliable solution is to use [[...]] or
to use test and [] only in cases that are defined by the standard.
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users