What are the contexts where Bash doesn't perform word splitting and globbing?

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Bash doesn't perform word splitting in globbing in these cases:
LHS or RHS of an assignment, except for indexed arrays
var=$value # simple variable
declare -A hash
key="key with a space"
hash[$key]=$value # index of an associative array
arr=$(echo "1 2 3") # word splitting does happen here
Inside [[ ]]
var="one two"
if [[ $var = *" "* ]]; then ... # check if var has a space in it
if [[ $(echo "one two") = $var ]]; then # use the output of command substitution to compare with var
Inside (( ))
((sum = $(echo "99 + 1"))) # assigns 100 to sum
In herestring
cat <<< * # gives '*' as the output
Is there a definite list of cases where Bash does or doesn't perform word splitting and globbing?
bash wildcards variable-substitution syntax
add a comment |Â
up vote
2
down vote
favorite
Bash doesn't perform word splitting in globbing in these cases:
LHS or RHS of an assignment, except for indexed arrays
var=$value # simple variable
declare -A hash
key="key with a space"
hash[$key]=$value # index of an associative array
arr=$(echo "1 2 3") # word splitting does happen here
Inside [[ ]]
var="one two"
if [[ $var = *" "* ]]; then ... # check if var has a space in it
if [[ $(echo "one two") = $var ]]; then # use the output of command substitution to compare with var
Inside (( ))
((sum = $(echo "99 + 1"))) # assigns 100 to sum
In herestring
cat <<< * # gives '*' as the output
Is there a definite list of cases where Bash does or doesn't perform word splitting and globbing?
bash wildcards variable-substitution syntax
cat <<< $vardoes word splitting (followed by joining with space) but not globbing in older versions. For redirections, that depends on whether the posix/sh mode is enabled and the shell is interactive or not.
â Stéphane Chazelas
May 4 at 13:18
Related: What is (exactly) "list context" (and "string context")?
â Stéphane Chazelas
May 4 at 13:21
Note that "indexed array" is the retronym for ordinary arrays, in contrast to associative array. You are talking about the index to an associative array.
â chepner
May 4 at 17:43
1
case $foo inis another. I'm not sure about arguments to parameter expansion;foo="a * b"survives unexpanded in both"$bar:-$foo"and$bar:-"$foo". I don't recall the details, but I think there is a comment in the source to the effect that the argument itself is not subject to word-splitting or pathname expansion.
â chepner
May 4 at 17:51
I asked the same question on StackOverflow to see if it gets more attention there.
â codeforester
May 25 at 23:30
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Bash doesn't perform word splitting in globbing in these cases:
LHS or RHS of an assignment, except for indexed arrays
var=$value # simple variable
declare -A hash
key="key with a space"
hash[$key]=$value # index of an associative array
arr=$(echo "1 2 3") # word splitting does happen here
Inside [[ ]]
var="one two"
if [[ $var = *" "* ]]; then ... # check if var has a space in it
if [[ $(echo "one two") = $var ]]; then # use the output of command substitution to compare with var
Inside (( ))
((sum = $(echo "99 + 1"))) # assigns 100 to sum
In herestring
cat <<< * # gives '*' as the output
Is there a definite list of cases where Bash does or doesn't perform word splitting and globbing?
bash wildcards variable-substitution syntax
Bash doesn't perform word splitting in globbing in these cases:
LHS or RHS of an assignment, except for indexed arrays
var=$value # simple variable
declare -A hash
key="key with a space"
hash[$key]=$value # index of an associative array
arr=$(echo "1 2 3") # word splitting does happen here
Inside [[ ]]
var="one two"
if [[ $var = *" "* ]]; then ... # check if var has a space in it
if [[ $(echo "one two") = $var ]]; then # use the output of command substitution to compare with var
Inside (( ))
((sum = $(echo "99 + 1"))) # assigns 100 to sum
In herestring
cat <<< * # gives '*' as the output
Is there a definite list of cases where Bash does or doesn't perform word splitting and globbing?
bash wildcards variable-substitution syntax
edited May 4 at 13:02
asked May 4 at 1:42
codeforester
335314
335314
cat <<< $vardoes word splitting (followed by joining with space) but not globbing in older versions. For redirections, that depends on whether the posix/sh mode is enabled and the shell is interactive or not.
â Stéphane Chazelas
May 4 at 13:18
Related: What is (exactly) "list context" (and "string context")?
â Stéphane Chazelas
May 4 at 13:21
Note that "indexed array" is the retronym for ordinary arrays, in contrast to associative array. You are talking about the index to an associative array.
â chepner
May 4 at 17:43
1
case $foo inis another. I'm not sure about arguments to parameter expansion;foo="a * b"survives unexpanded in both"$bar:-$foo"and$bar:-"$foo". I don't recall the details, but I think there is a comment in the source to the effect that the argument itself is not subject to word-splitting or pathname expansion.
â chepner
May 4 at 17:51
I asked the same question on StackOverflow to see if it gets more attention there.
â codeforester
May 25 at 23:30
add a comment |Â
cat <<< $vardoes word splitting (followed by joining with space) but not globbing in older versions. For redirections, that depends on whether the posix/sh mode is enabled and the shell is interactive or not.
â Stéphane Chazelas
May 4 at 13:18
Related: What is (exactly) "list context" (and "string context")?
â Stéphane Chazelas
May 4 at 13:21
Note that "indexed array" is the retronym for ordinary arrays, in contrast to associative array. You are talking about the index to an associative array.
â chepner
May 4 at 17:43
1
case $foo inis another. I'm not sure about arguments to parameter expansion;foo="a * b"survives unexpanded in both"$bar:-$foo"and$bar:-"$foo". I don't recall the details, but I think there is a comment in the source to the effect that the argument itself is not subject to word-splitting or pathname expansion.
â chepner
May 4 at 17:51
I asked the same question on StackOverflow to see if it gets more attention there.
â codeforester
May 25 at 23:30
cat <<< $var does word splitting (followed by joining with space) but not globbing in older versions. For redirections, that depends on whether the posix/sh mode is enabled and the shell is interactive or not.â Stéphane Chazelas
May 4 at 13:18
cat <<< $var does word splitting (followed by joining with space) but not globbing in older versions. For redirections, that depends on whether the posix/sh mode is enabled and the shell is interactive or not.â Stéphane Chazelas
May 4 at 13:18
Related: What is (exactly) "list context" (and "string context")?
â Stéphane Chazelas
May 4 at 13:21
Related: What is (exactly) "list context" (and "string context")?
â Stéphane Chazelas
May 4 at 13:21
Note that "indexed array" is the retronym for ordinary arrays, in contrast to associative array. You are talking about the index to an associative array.
â chepner
May 4 at 17:43
Note that "indexed array" is the retronym for ordinary arrays, in contrast to associative array. You are talking about the index to an associative array.
â chepner
May 4 at 17:43
1
1
case $foo in is another. I'm not sure about arguments to parameter expansion; foo="a * b" survives unexpanded in both "$bar:-$foo" and $bar:-"$foo". I don't recall the details, but I think there is a comment in the source to the effect that the argument itself is not subject to word-splitting or pathname expansion.â chepner
May 4 at 17:51
case $foo in is another. I'm not sure about arguments to parameter expansion; foo="a * b" survives unexpanded in both "$bar:-$foo" and $bar:-"$foo". I don't recall the details, but I think there is a comment in the source to the effect that the argument itself is not subject to word-splitting or pathname expansion.â chepner
May 4 at 17:51
I asked the same question on StackOverflow to see if it gets more attention there.
â codeforester
May 25 at 23:30
I asked the same question on StackOverflow to see if it gets more attention there.
â codeforester
May 25 at 23:30
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Â
draft saved
draft discarded
Â
draft saved
draft discarded
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%2f441690%2fwhat-are-the-contexts-where-bash-doesnt-perform-word-splitting-and-globbing%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
cat <<< $vardoes word splitting (followed by joining with space) but not globbing in older versions. For redirections, that depends on whether the posix/sh mode is enabled and the shell is interactive or not.â Stéphane Chazelas
May 4 at 13:18
Related: What is (exactly) "list context" (and "string context")?
â Stéphane Chazelas
May 4 at 13:21
Note that "indexed array" is the retronym for ordinary arrays, in contrast to associative array. You are talking about the index to an associative array.
â chepner
May 4 at 17:43
1
case $foo inis another. I'm not sure about arguments to parameter expansion;foo="a * b"survives unexpanded in both"$bar:-$foo"and$bar:-"$foo". I don't recall the details, but I think there is a comment in the source to the effect that the argument itself is not subject to word-splitting or pathname expansion.â chepner
May 4 at 17:51
I asked the same question on StackOverflow to see if it gets more attention there.
â codeforester
May 25 at 23:30