In zsh, what is the meaning of the ‘$==*’ idiom

zsh

I have found the $==* idiom in several zsh solutions that I use. It seems to be equivalent to $argv. But I don't know how it gets interpreted. Could you explain?

Best Answer

This is one of Zsh's parameter expansions here applied to $*:

${=spec}
Perform word splitting using the rules for SH_WORD_SPLIT during the evaluation of spec, but regardless of whether the parameter appears in double quotes; if the ‘=’ is doubled, turn it off. This forces parameter expansions to be split into separate words before substitution, using IFS as a delimiter. This is done by default in most other shells.

See Gilles' typically thorough answer to What is word splitting? Why is it important in shell programming for context.

Normally, zsh doesn't do word splitting by default, so presumably, that's to make sure $* is not split even when the SH_WORD_SPLIT option has been enabled one way or another (for instance via a emulate sh).

However, in most cases, you'd rather want to use "$@" (note the quotes which are important here) instead of $==*. $==* (like $* when SH_WORD_SPLIT is off) expands only to the non-empty positional parameters, while "$@" expands to all the positional parameters (regardless of SH_WORD_SPLIT, and that works in all Bourne-like shells).

Related Question