Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Why does builtin 'test' differ from /usr/bin/test



On Tue, Jan 09, 2007 at 08:38:58AM +0100, Com MN PG P E B Consultant 3 wrote:
> From the zsh manpages:
> 
>   "test [ arg ... ]
>        [ [ arg ... ] ]
>               Like the system version of test.  Added for  compatibility;"...
> 
> But in zsh, the following two commands yield different results:
> 
>   test -a = '-?' -o -a = '?' && echo true           # true
>   command test -a = '-?' -o -a = '?' && echo true   # not true
> 
> Why is the first (builtin) test true?	
[...]

In short because the behavior of test for more than 4 arguments
is unspecified.

Use:

test -a = '-?' || test -a = '?'

or:

case -a in
  '?' | '-?') ...;;
esac


BTW, for me both return "not true".

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author