Skip to main content
added 590 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

Word splitting is not part of the syntax parsing. It's like an operator that is applied implicitly to arguments (also in for loop words, arrays and with some shell the target of redirections and a few other contexts) for the parts of them that are not quoted. What's confusing is that it's done implicitly. You don't do cmd split($x), you do cmd $x and the split() (actually glob(split())) is implied. In zsh, you have to request it explicitly for parameter expansions (split($x) is $=x there ($= looking like a pair of scissors)).

So, now, for your examples:

So for your examples:

Word splitting is not part of the syntax parsing. It's like an operator that is applied implicitly to arguments (also in for loop words, arrays and with some shell the target of redirections and a few other contexts) for the parts of them that are not quoted. What's confusing is that it's done implicitly. You don't do cmd split($x), you do cmd $x and the split() (actually glob(split())) is implied. In zsh, you have to request it explicitly for parameter expansions (split($x) is $=x there ($= looking like a pair of scissors)).

So, now, for your examples:

added 83 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

Word splitting only applies to unquoted expansions (parameter expansion, arithmetic expansion and command substitution) in modern Bourne-like shells (in zsh, only command substitution unless you use an emulation mode).

Word splitting only applies to unquoted expansions (parameter expansion, arithmetic expansion and command substitution) in modern shells.

Word splitting only applies to unquoted expansions (parameter expansion, arithmetic expansion and command substitution) in modern Bourne-like shells (in zsh, only command substitution unless you use an emulation mode).

added 464 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

It's the shell parsing that tokenises those, finds the first one is not one of its keywords and so it's a simple command with 3 arguments: args, a and :b. The amount of space won't make any difference there. Note that it's not only spaces, also tabs, and in some shells (like yash or bash) any character considered as blank in you locale (though in the case of bash, not the multibyte ones)¹.

IFS=i
while bib=did edit foo
"wh" "le b" "b=d" "d ed" "t foo"

But first as a while with a simple command and the edit word (as it's an argument but not the bid=did word which is an assignment) of that simple command would be further split into ed and t so that the ed command with the 3 arguments ed, t and foo would be run as the condition of that while loop.

you'd see <ab> as the information that a and b were 2 separate arguments was lost when assigned to $var.


¹, of course, it's not only blanks that delimit words. Special tokens in the shell syntax do as well, the list of which depends on the context. In most contexts, |, ||, &, ;, newline, <, >, >>... delimit words. In ksh93 for instance, you can write a blank-less command like:

while({([[(:)]])})&&((1||1))do(:);uname<&2|tee>(rev)file;done

It's the shell parsing that tokenises those, finds the first one is not one of its keywords and so it's a simple command with 3 arguments: args, a and :b. The amount of space won't make any difference there. Note that it's not only spaces, also tabs, and in some shells (like yash or bash) any character considered as blank in you locale (though in the case of bash, not the multibyte ones).

IFS=i
while edit foo
"wh" "le ed" "t foo"

But first as a while with a simple command and the edit word of that simple command would be further split into ed and t so that the ed command with the 3 arguments ed, t and foo would be run as the condition of that while loop.

you'd see <ab> as the information that a and b were 2 separate arguments was lost when assigned to $var.

It's the shell parsing that tokenises those, finds the first one is not one of its keywords and so it's a simple command with 3 arguments: args, a and :b. The amount of space won't make any difference there. Note that it's not only spaces, also tabs, and in some shells (like yash or bash) any character considered as blank in you locale (though in the case of bash, not the multibyte ones)¹.

IFS=i
while bib=did edit foo
"wh" "le b" "b=d" "d ed" "t foo"

But first as a while with a simple command and the edit word (as it's an argument but not the bid=did word which is an assignment) of that simple command would be further split into ed and t so that the ed command with the 3 arguments ed, t and foo would be run as the condition of that while loop.

you'd see <ab> as the information that a and b were 2 separate arguments was lost when assigned to $var.


¹, of course, it's not only blanks that delimit words. Special tokens in the shell syntax do as well, the list of which depends on the context. In most contexts, |, ||, &, ;, newline, <, >, >>... delimit words. In ksh93 for instance, you can write a blank-less command like:

while({([[(:)]])})&&((1||1))do(:);uname<&2|tee>(rev)file;done
added 1 character in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
Loading
added 818 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
Loading
added 818 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
Loading
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
Loading