Implicit word splitting, i.e. word splitting on an unquoted variable expansion ($foo
as opposed to "$foo"
), is something that all POSIX compliant shells do, and more generally all sh
shells. They also perform globbing on the result. This is why you need double quotes around variable substitutions. The same goes for command substitutions.
POSIX calls these field splitting and pathname expansion.
Zsh deviates from the standard sh behavior. It doesn't perform word splitting on unquoted variable substitutions (but it does perform word splitting on unquoted command substitutions), and it doesn't perform globbing on unquoted substitutions at all. (Zsh has those features, of course, but they're explicit: $=foo
to do word splitting and $~foo
to do globbing.) Zsh is not an sh-compatible shell; it's fairly close, but not compatible, and the reduced implicit splitting is one of the main deviations.
Zsh has a compatibility mode (which is entered automatically if the zsh executable is called sh
or ksh
) in which it does perform implicit word splitting and globbing like sh, among other things.
Bash and ksh are both sh-compatible shells. Bash does have a few incompatibilities with POSIX, but you have to dig a lot deeper to find them. On important issues like implicit splitting, it's compatible.
(T)csh is a completely different family of shells. Its syntax is vastly different from sh. It's also pretty much dead, so don't worry about it.
$=var
instead of$var
. Same for globbing upon expansions, another thing that is done implicitly by POSIX shells and is about as dangerous/unwanted as word splitting:$~var
instead of$var
. So$var
in POSIX shells is like$=~var
inzsh
. – Stéphane Chazelas Jan 23 '18 at 20:12