On Fri, Jun 1, 2012 at 8:04 AM, Clark WANG <[email protected]> wrote:
> On Fri, Jun 1, 2012 at 1:58 PM, Clark WANG <[email protected]> wrote:
>> For example:
>>
>> $ echo ${.sh.version}
>> Version JMP 93u+ 2012-05-17
>> $
>> $ [ -n hello world ] && echo yes
>> yes
>> $
>
> More example:
>
> $ [ -z "" foo bar ] && echo yes
> yes
> $ [ -d / foo bar ] && echo yes
> yes
> $ [ -o glob foo bar ] && echo yes
> yes
> $ [ -n foo -n bar ] && echo yes
> yes
> $ [ -n foo -n '' ] && echo yes
> yes
> $ [ foo = foo bar ] && echo yes
> yes
> $
>
>>
>> In Bash I got:
>>
>> $ echo $BASH_VERSION
>> 4.2.20(1)-release
>> $
>> $ [ -n hello world ] && echo yes
>> bash: [: hello: binary operator expected
>> $
>>
>> In Zsh I got:
>>
>> $ echo $ZSH_VERSION
>> 4.3.12
>> $
>> $ [ -n hello world ] && echo yes
>> [: too many arguments
>> $

If you have values with white spaces, i.e. the characters listed in
the IFS variable, you should use ' or " to wrap them.
Example:
[ -n "hello world" ]

Otherwise you end up with behaviour undefined by the POSIX and SUS standards.
My recommendation for handling file names with white spaces is either
to set IFS to '' (empty string) or (or both) always use proper quoting
and the [[ ]] expressions instead of the test builtin (alias [).

Irek
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to