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

Parser issues and and [[ $var ]]



On Apr 26, 10:07am, Martin Vaeth wrote:
}
} BTW: "emulate -L bash" would be useful to read some distribution's
} or user's bash setup files. Main difference to emulate -L sh would be
}   setopt ksh_glob no_sh_glob brace_expand
} and that [[ $var ]] is treated equivalent to [[ -n $var ]]:
} I experienced that the latter is the main issue with bash compatibility
} (besides shopt and PS1, of course, which are not reasonable to emulate).

Hmm.  Looks like both bash and ksh93 accept [[ $foo ]] as valid syntax.
This turns out to be surprisingly difficult to fix, and poking at it,
I think we may have broken some things in parse.c.

For example, [ -t ] is supposed to be equivalent to [ -t 1 ] and there
is code late in par_cond_2() that handles this, but that code is never
reached because the /* POSIX 1003.2 */ code at the top of par_cond_2()
preemptively turns it into [ -n -t ].

The same unreached code for [ -t ] also tries to handle [ $var ] but is
not usable for [[ $var ]] because of the different lexing conventions
for "test"/"[" vs. [[ ... ]].  Also [[ -t ]] is NOT supposed to behave
like either of [[ -t 1 ]] or [[ -n -t ]], so that part of the code in
question must be avoided.

Also, if you compare the later code to the earlier code, sometimes we
call dupstring() on the first argument to par_cond_double() and other
times we do not.  Either we don't need dupstring(), or not using it is
a bug waiting to happen.

So it looks like par_cond_2() needs some more overhauling.



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