I'm getting confused about the role word splitting plays in zsh
. I have not been exposed to this concept when programming in C, Python or MATLAB, and this has triggered my interest of why word splitting seems to be something specific to shell programming.
I have read about word splitting on this and other sites before, but haven't found a clear explanation of the concept. Wikipedia has a definition of word splitting but does not seem to have references on how it applies to Unix shells.
Here's an example of my confusion in zsh
:
In the Z Shell FAQ, I read the following:
3.1: Why does
$var
wherevar="foo bar"
not do what I expect?In most Bourne-shell derivatives, multiple-word variables such as
var="foo bar"
are split into words when passed to a command or used in afor foo in $var
loop. By default, zsh does not have that behaviour: the variable remains intact. (This is not a bug! See below.) The optionSH_WORD_SPLIT
exists to provide compatibility.
However, in the Z Shell Manual, I read the following:
SH_WORD_SPLIT (-y) <K> <S>
Causes field splitting to be performed on unquoted parameter expansions. Note that this option has nothing to do with word splitting. (See Parameter Expansion.)
Why does it say that SH_WORD_SPLIT
has nothing to do with word splitting? Isn't word splitting precisely what this is all about?
"word1 word2 word3"
into lists/arrays of the form"word1" "word2" "word3"
? I have also updated the OP with a specific source of confusion in zsh. – Amelio Vazquez-Reina Dec 13 '11 at 01:56$IFS
characters. Hence "field splitting" is a better name. But "word splitting" is often used for this concept in shell literature. The zsh documentation is quibbling on words. – Gilles 'SO- stop being evil' Dec 14 '11 at 10:11rc
(the plan9 shell, also ported to Unix) for an even better design than zsh when it comes to variables and arrays. – Stéphane Chazelas Feb 08 '13 at 23:17