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

Builtin test and parsing of conditionals



According to some discussion on the austin-group (POSIX) mailing list,
the following:

	test ! -a !
	test ! -o !
	test ! = !

should all be parsed as comparing the string "!" to the string "!", but
zsh gets this right only in the last case.

This is especially annoying because

	test ! -f !

should be interpreted as the negation of the unary file-exists operator.

This is probably complicated by the different meanings of -a and -o in
[[ ... ]] as opposed to "test" because the same parser is used.

Furthermore:

	test ! = -o a

should be parsed as the negation of the comparison between the strings "="
and "a", implying that zsh also gets this wrong:

	test ! = = =

which should return false (negation of (equal is the same string as equal)),
rather than give a parse error as zsh does.  (Zsh does get

	test = = =

right.)

Apparently the only way to do this correctly is to examine both argv[1] and
the number of arguments, and skip to argv[2] for recursive descent parsing
when argv[1] is "!" and there are four arguments.  (As already mentioned in
the zsh manual, what to do with more than four arguments in the absence of
explicit parens is unclear [unspecified?].)



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