Is word splitting a part of POSIX?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard.
In other words, does sh
have word splitting, or is it a Bash-only feature? If I wanted to write a portable shell script, would I have to account for word splitting, or is it something nonstandard that is added by other shells?
bash shell-script portability
add a comment |Â
up vote
3
down vote
favorite
I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard.
In other words, does sh
have word splitting, or is it a Bash-only feature? If I wanted to write a portable shell script, would I have to account for word splitting, or is it something nonstandard that is added by other shells?
bash shell-script portability
zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request 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 at 20:12
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard.
In other words, does sh
have word splitting, or is it a Bash-only feature? If I wanted to write a portable shell script, would I have to account for word splitting, or is it something nonstandard that is added by other shells?
bash shell-script portability
I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard.
In other words, does sh
have word splitting, or is it a Bash-only feature? If I wanted to write a portable shell script, would I have to account for word splitting, or is it something nonstandard that is added by other shells?
bash shell-script portability
edited Apr 1 at 8:27
codeforester
336314
336314
asked Jan 23 at 17:54
3p1k5auc3
232
232
zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request 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 at 20:12
add a comment |Â
zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request 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 at 20:12
zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request 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
in zsh
.â Stéphane Chazelas
Jan 23 at 20:12
zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request 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
in zsh
.â Stéphane Chazelas
Jan 23 at 20:12
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
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.
Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
â 3p1k5auc3
Jan 24 at 16:33
add a comment |Â
up vote
2
down vote
Field splitting
is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.
The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
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.
Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
â 3p1k5auc3
Jan 24 at 16:33
add a comment |Â
up vote
4
down vote
accepted
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.
Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
â 3p1k5auc3
Jan 24 at 16:33
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
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.
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.
answered Jan 23 at 23:20
Gilles
506k11910011529
506k11910011529
Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
â 3p1k5auc3
Jan 24 at 16:33
add a comment |Â
Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
â 3p1k5auc3
Jan 24 at 16:33
Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
â 3p1k5auc3
Jan 24 at 16:33
Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
â 3p1k5auc3
Jan 24 at 16:33
add a comment |Â
up vote
2
down vote
Field splitting
is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.
The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.
add a comment |Â
up vote
2
down vote
Field splitting
is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.
The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Field splitting
is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.
The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.
Field splitting
is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.
The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.
answered Jan 23 at 18:54
Patrick Mevzek
2,0131721
2,0131721
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f419148%2fis-word-splitting-a-part-of-posix%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request 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 at 20:12