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

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question





















  • 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










  • 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 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















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?







share|improve this question





















  • 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










  • 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 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













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?







share|improve this question













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?









share|improve this question












share|improve this question




share|improve this question








edited May 4 at 13:02
























asked May 4 at 1:42









codeforester

335314




335314











  • 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










  • 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 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

















  • 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










  • 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 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
















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
















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)