Is `echo $TEST` expanding an asterisk in the variable a bug? [duplicate]Why does my shell script choke on whitespace or other special characters?Security implications of forgetting to quote a variable in bash/POSIX shellsWhen is double-quoting necessary?Why is bash extended-globbing variable substitution acting at the byte level?In bash, how can I echo the variable name, not the variable value?Why does `bash -c somecommand` sometimes not leave a bash process?Why does BASH process substitution not work with some commands?Bash regex string manipulation bugecho \* - bash backslash escape behavior, is it evaluated backwards?Why there is such a difference in execution time of echo and cat?Expanding a brace expansion string held in a variable for use in a for loop?have I found a bug in BASH?bash and expect in the same script?
Boss wants someone else to lead a project based on the idea I presented to him
Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?
Are there any individual aliens that have gained superpowers in the Marvel universe?
Justifying Affordable Bespoke Spaceships
Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?
How did Gollum enter Moria?
What is the "ls" directory in my home directory?
Second 100 amp breaker inside existing 200 amp residential panel for new detached garage
Proving an Intuitive Result Rigorously
How do I remove this inheritance-related code smell?
Extending prime numbers digit by digit while retaining primality
Value matching with NA - missing values - using mutate
Should I include an appendix for inessential, yet related worldbuilding to my story?
Why don't we have a weaning party like Avraham did?
How could empty set be unique if it could be vacuously false
Designing a magic-compatible polearm
Cut the gold chain
Did the CIA blow up a Siberian pipeline in 1982?
Are there examples of rowers who also fought?
King or Queen-Which piece is which?
What triggered jesuits' ban on infinitesimals in 1632?
Dmesg full of I/O errors, smart ok, four disks affected
Why is oilcloth made with linseed oil?
What was the first third-party commercial application for MS-DOS?
Is `echo $TEST` expanding an asterisk in the variable a bug? [duplicate]
Why does my shell script choke on whitespace or other special characters?Security implications of forgetting to quote a variable in bash/POSIX shellsWhen is double-quoting necessary?Why is bash extended-globbing variable substitution acting at the byte level?In bash, how can I echo the variable name, not the variable value?Why does `bash -c somecommand` sometimes not leave a bash process?Why does BASH process substitution not work with some commands?Bash regex string manipulation bugecho \* - bash backslash escape behavior, is it evaluated backwards?Why there is such a difference in execution time of echo and cat?Expanding a brace expansion string held in a variable for use in a for loop?have I found a bug in BASH?bash and expect in the same script?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
Security implications of forgetting to quote a variable in bash/POSIX shells
3 answers
When is double-quoting necessary?
1 answer
Is this a Bash bug?
$ mkdir test && cd test && echo "a" > "some.file"
test$ echo '*'
*
test$ TEST=$(echo '*')
test$ echo $TEST
some.file
Why is the second output the resolution of *
into (all) filenames instead of just a literal *
output? Looks like a bug in Bash?
Tried on Ubuntu 18.04, bash version 4.4.19(1)-release. Expect it will be the same on other OS'es.
bash shell quoting command-substitution variable-substitution
marked as duplicate by muru, Scott, ilkkachu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jun 3 at 19:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
Security implications of forgetting to quote a variable in bash/POSIX shells
3 answers
When is double-quoting necessary?
1 answer
Is this a Bash bug?
$ mkdir test && cd test && echo "a" > "some.file"
test$ echo '*'
*
test$ TEST=$(echo '*')
test$ echo $TEST
some.file
Why is the second output the resolution of *
into (all) filenames instead of just a literal *
output? Looks like a bug in Bash?
Tried on Ubuntu 18.04, bash version 4.4.19(1)-release. Expect it will be the same on other OS'es.
bash shell quoting command-substitution variable-substitution
marked as duplicate by muru, Scott, ilkkachu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jun 3 at 19:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
General procedure when finding bugs in Unix: 1) Check out Single Unix Specification online for relevant definitions and rationales. 2) Submit a bugreport to austingroupbugs.net 3) Submit bugreport to the developer (with a patch if possible).
– DannyNiu
Jun 3 at 1:10
3
@DannyNiu: Your comment is not very practical. Documents like POSIX and the Single Unix Specification do not consist of millions and millions of examples; they contain explanations (with, maybe, a few examples). Those documents are of little help to somebody who doesn’t understand what is happening and why; reading them is like learning to drive by reading a roadmap. And this question isn’t asking what to do. If you want to post a question, “What should I do if I’ve found a bug in a widely used software product?”, and post an answer, go ahead.
– G-Man
Jun 3 at 4:26
@G-Man I did find DannyNiu's answer helpful in terms of the information provided, "just in case".
– Roel
Jun 3 at 4:28
add a comment |
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
Security implications of forgetting to quote a variable in bash/POSIX shells
3 answers
When is double-quoting necessary?
1 answer
Is this a Bash bug?
$ mkdir test && cd test && echo "a" > "some.file"
test$ echo '*'
*
test$ TEST=$(echo '*')
test$ echo $TEST
some.file
Why is the second output the resolution of *
into (all) filenames instead of just a literal *
output? Looks like a bug in Bash?
Tried on Ubuntu 18.04, bash version 4.4.19(1)-release. Expect it will be the same on other OS'es.
bash shell quoting command-substitution variable-substitution
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
Security implications of forgetting to quote a variable in bash/POSIX shells
3 answers
When is double-quoting necessary?
1 answer
Is this a Bash bug?
$ mkdir test && cd test && echo "a" > "some.file"
test$ echo '*'
*
test$ TEST=$(echo '*')
test$ echo $TEST
some.file
Why is the second output the resolution of *
into (all) filenames instead of just a literal *
output? Looks like a bug in Bash?
Tried on Ubuntu 18.04, bash version 4.4.19(1)-release. Expect it will be the same on other OS'es.
This question already has an answer here:
Why does my shell script choke on whitespace or other special characters?
4 answers
Security implications of forgetting to quote a variable in bash/POSIX shells
3 answers
When is double-quoting necessary?
1 answer
bash shell quoting command-substitution variable-substitution
bash shell quoting command-substitution variable-substitution
edited Jun 3 at 18:00
Gilles
559k13411471657
559k13411471657
asked Jun 3 at 0:16
RoelRoel
1267
1267
marked as duplicate by muru, Scott, ilkkachu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jun 3 at 19:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by muru, Scott, ilkkachu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jun 3 at 19:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
General procedure when finding bugs in Unix: 1) Check out Single Unix Specification online for relevant definitions and rationales. 2) Submit a bugreport to austingroupbugs.net 3) Submit bugreport to the developer (with a patch if possible).
– DannyNiu
Jun 3 at 1:10
3
@DannyNiu: Your comment is not very practical. Documents like POSIX and the Single Unix Specification do not consist of millions and millions of examples; they contain explanations (with, maybe, a few examples). Those documents are of little help to somebody who doesn’t understand what is happening and why; reading them is like learning to drive by reading a roadmap. And this question isn’t asking what to do. If you want to post a question, “What should I do if I’ve found a bug in a widely used software product?”, and post an answer, go ahead.
– G-Man
Jun 3 at 4:26
@G-Man I did find DannyNiu's answer helpful in terms of the information provided, "just in case".
– Roel
Jun 3 at 4:28
add a comment |
2
General procedure when finding bugs in Unix: 1) Check out Single Unix Specification online for relevant definitions and rationales. 2) Submit a bugreport to austingroupbugs.net 3) Submit bugreport to the developer (with a patch if possible).
– DannyNiu
Jun 3 at 1:10
3
@DannyNiu: Your comment is not very practical. Documents like POSIX and the Single Unix Specification do not consist of millions and millions of examples; they contain explanations (with, maybe, a few examples). Those documents are of little help to somebody who doesn’t understand what is happening and why; reading them is like learning to drive by reading a roadmap. And this question isn’t asking what to do. If you want to post a question, “What should I do if I’ve found a bug in a widely used software product?”, and post an answer, go ahead.
– G-Man
Jun 3 at 4:26
@G-Man I did find DannyNiu's answer helpful in terms of the information provided, "just in case".
– Roel
Jun 3 at 4:28
2
2
General procedure when finding bugs in Unix: 1) Check out Single Unix Specification online for relevant definitions and rationales. 2) Submit a bugreport to austingroupbugs.net 3) Submit bugreport to the developer (with a patch if possible).
– DannyNiu
Jun 3 at 1:10
General procedure when finding bugs in Unix: 1) Check out Single Unix Specification online for relevant definitions and rationales. 2) Submit a bugreport to austingroupbugs.net 3) Submit bugreport to the developer (with a patch if possible).
– DannyNiu
Jun 3 at 1:10
3
3
@DannyNiu: Your comment is not very practical. Documents like POSIX and the Single Unix Specification do not consist of millions and millions of examples; they contain explanations (with, maybe, a few examples). Those documents are of little help to somebody who doesn’t understand what is happening and why; reading them is like learning to drive by reading a roadmap. And this question isn’t asking what to do. If you want to post a question, “What should I do if I’ve found a bug in a widely used software product?”, and post an answer, go ahead.
– G-Man
Jun 3 at 4:26
@DannyNiu: Your comment is not very practical. Documents like POSIX and the Single Unix Specification do not consist of millions and millions of examples; they contain explanations (with, maybe, a few examples). Those documents are of little help to somebody who doesn’t understand what is happening and why; reading them is like learning to drive by reading a roadmap. And this question isn’t asking what to do. If you want to post a question, “What should I do if I’ve found a bug in a widely used software product?”, and post an answer, go ahead.
– G-Man
Jun 3 at 4:26
@G-Man I did find DannyNiu's answer helpful in terms of the information provided, "just in case".
– Roel
Jun 3 at 4:28
@G-Man I did find DannyNiu's answer helpful in terms of the information provided, "just in case".
– Roel
Jun 3 at 4:28
add a comment |
1 Answer
1
active
oldest
votes
No, it is not a bug. You have shown that
echo '*'
will produce a literal *
. Hence when you substitute this output, as per the following command
TEST=$(echo '*')
it will put *
into the variable $TEST
. Then when you
echo $TEST
the glob will expand here. You can verify this by running this last command, changing directories, then running it again.
You will get the *
output if you say
echo "$TEST"
as explained here,
the double quotes allow the variable to be expanded
but prevent the glob from expanding.
Aha, I see. Thank you. I missed the fact that the echo * does not have quotes and thus resolves. It's harder to see when you have it inside a complex script :) Makes sense now.
– Roel
Jun 3 at 1:36
3
@Roel FWIW, after a few years of experience you will start to treat$TEST
instead of"$TEST"
as a code smell and it becomes a bit easier to see. It's still not much of a smell though so it will still trip you up sometimes
– slebetman
Jun 3 at 9:24
8
And this is why my general approach is, if it starts with a dollar, quote it :). Yes, you CAN learn the specific cases where you don't have to - but it's almost always harmless to quote them in cases where you don't have to, so you may as well just quote your variables everywhere!
– Muzer
Jun 3 at 10:15
2
@slebetman: And for the rest of us without this instinct,shellcheck
will do the complaining ( shellcheck.net ).
– Piskvor
Jun 3 at 12:42
3
@Roel many decades ago, I learned -- the hard way -- that 99.99999% of the time it's your fault, not a bug in the compiler or interpreter... :)
– RonJohn
Jun 3 at 14:56
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
No, it is not a bug. You have shown that
echo '*'
will produce a literal *
. Hence when you substitute this output, as per the following command
TEST=$(echo '*')
it will put *
into the variable $TEST
. Then when you
echo $TEST
the glob will expand here. You can verify this by running this last command, changing directories, then running it again.
You will get the *
output if you say
echo "$TEST"
as explained here,
the double quotes allow the variable to be expanded
but prevent the glob from expanding.
Aha, I see. Thank you. I missed the fact that the echo * does not have quotes and thus resolves. It's harder to see when you have it inside a complex script :) Makes sense now.
– Roel
Jun 3 at 1:36
3
@Roel FWIW, after a few years of experience you will start to treat$TEST
instead of"$TEST"
as a code smell and it becomes a bit easier to see. It's still not much of a smell though so it will still trip you up sometimes
– slebetman
Jun 3 at 9:24
8
And this is why my general approach is, if it starts with a dollar, quote it :). Yes, you CAN learn the specific cases where you don't have to - but it's almost always harmless to quote them in cases where you don't have to, so you may as well just quote your variables everywhere!
– Muzer
Jun 3 at 10:15
2
@slebetman: And for the rest of us without this instinct,shellcheck
will do the complaining ( shellcheck.net ).
– Piskvor
Jun 3 at 12:42
3
@Roel many decades ago, I learned -- the hard way -- that 99.99999% of the time it's your fault, not a bug in the compiler or interpreter... :)
– RonJohn
Jun 3 at 14:56
|
show 1 more comment
No, it is not a bug. You have shown that
echo '*'
will produce a literal *
. Hence when you substitute this output, as per the following command
TEST=$(echo '*')
it will put *
into the variable $TEST
. Then when you
echo $TEST
the glob will expand here. You can verify this by running this last command, changing directories, then running it again.
You will get the *
output if you say
echo "$TEST"
as explained here,
the double quotes allow the variable to be expanded
but prevent the glob from expanding.
Aha, I see. Thank you. I missed the fact that the echo * does not have quotes and thus resolves. It's harder to see when you have it inside a complex script :) Makes sense now.
– Roel
Jun 3 at 1:36
3
@Roel FWIW, after a few years of experience you will start to treat$TEST
instead of"$TEST"
as a code smell and it becomes a bit easier to see. It's still not much of a smell though so it will still trip you up sometimes
– slebetman
Jun 3 at 9:24
8
And this is why my general approach is, if it starts with a dollar, quote it :). Yes, you CAN learn the specific cases where you don't have to - but it's almost always harmless to quote them in cases where you don't have to, so you may as well just quote your variables everywhere!
– Muzer
Jun 3 at 10:15
2
@slebetman: And for the rest of us without this instinct,shellcheck
will do the complaining ( shellcheck.net ).
– Piskvor
Jun 3 at 12:42
3
@Roel many decades ago, I learned -- the hard way -- that 99.99999% of the time it's your fault, not a bug in the compiler or interpreter... :)
– RonJohn
Jun 3 at 14:56
|
show 1 more comment
No, it is not a bug. You have shown that
echo '*'
will produce a literal *
. Hence when you substitute this output, as per the following command
TEST=$(echo '*')
it will put *
into the variable $TEST
. Then when you
echo $TEST
the glob will expand here. You can verify this by running this last command, changing directories, then running it again.
You will get the *
output if you say
echo "$TEST"
as explained here,
the double quotes allow the variable to be expanded
but prevent the glob from expanding.
No, it is not a bug. You have shown that
echo '*'
will produce a literal *
. Hence when you substitute this output, as per the following command
TEST=$(echo '*')
it will put *
into the variable $TEST
. Then when you
echo $TEST
the glob will expand here. You can verify this by running this last command, changing directories, then running it again.
You will get the *
output if you say
echo "$TEST"
as explained here,
the double quotes allow the variable to be expanded
but prevent the glob from expanding.
edited Jun 3 at 4:37
G-Man
14.7k94175
14.7k94175
answered Jun 3 at 0:22
SparhawkSparhawk
10.8k849102
10.8k849102
Aha, I see. Thank you. I missed the fact that the echo * does not have quotes and thus resolves. It's harder to see when you have it inside a complex script :) Makes sense now.
– Roel
Jun 3 at 1:36
3
@Roel FWIW, after a few years of experience you will start to treat$TEST
instead of"$TEST"
as a code smell and it becomes a bit easier to see. It's still not much of a smell though so it will still trip you up sometimes
– slebetman
Jun 3 at 9:24
8
And this is why my general approach is, if it starts with a dollar, quote it :). Yes, you CAN learn the specific cases where you don't have to - but it's almost always harmless to quote them in cases where you don't have to, so you may as well just quote your variables everywhere!
– Muzer
Jun 3 at 10:15
2
@slebetman: And for the rest of us without this instinct,shellcheck
will do the complaining ( shellcheck.net ).
– Piskvor
Jun 3 at 12:42
3
@Roel many decades ago, I learned -- the hard way -- that 99.99999% of the time it's your fault, not a bug in the compiler or interpreter... :)
– RonJohn
Jun 3 at 14:56
|
show 1 more comment
Aha, I see. Thank you. I missed the fact that the echo * does not have quotes and thus resolves. It's harder to see when you have it inside a complex script :) Makes sense now.
– Roel
Jun 3 at 1:36
3
@Roel FWIW, after a few years of experience you will start to treat$TEST
instead of"$TEST"
as a code smell and it becomes a bit easier to see. It's still not much of a smell though so it will still trip you up sometimes
– slebetman
Jun 3 at 9:24
8
And this is why my general approach is, if it starts with a dollar, quote it :). Yes, you CAN learn the specific cases where you don't have to - but it's almost always harmless to quote them in cases where you don't have to, so you may as well just quote your variables everywhere!
– Muzer
Jun 3 at 10:15
2
@slebetman: And for the rest of us without this instinct,shellcheck
will do the complaining ( shellcheck.net ).
– Piskvor
Jun 3 at 12:42
3
@Roel many decades ago, I learned -- the hard way -- that 99.99999% of the time it's your fault, not a bug in the compiler or interpreter... :)
– RonJohn
Jun 3 at 14:56
Aha, I see. Thank you. I missed the fact that the echo * does not have quotes and thus resolves. It's harder to see when you have it inside a complex script :) Makes sense now.
– Roel
Jun 3 at 1:36
Aha, I see. Thank you. I missed the fact that the echo * does not have quotes and thus resolves. It's harder to see when you have it inside a complex script :) Makes sense now.
– Roel
Jun 3 at 1:36
3
3
@Roel FWIW, after a few years of experience you will start to treat
$TEST
instead of "$TEST"
as a code smell and it becomes a bit easier to see. It's still not much of a smell though so it will still trip you up sometimes– slebetman
Jun 3 at 9:24
@Roel FWIW, after a few years of experience you will start to treat
$TEST
instead of "$TEST"
as a code smell and it becomes a bit easier to see. It's still not much of a smell though so it will still trip you up sometimes– slebetman
Jun 3 at 9:24
8
8
And this is why my general approach is, if it starts with a dollar, quote it :). Yes, you CAN learn the specific cases where you don't have to - but it's almost always harmless to quote them in cases where you don't have to, so you may as well just quote your variables everywhere!
– Muzer
Jun 3 at 10:15
And this is why my general approach is, if it starts with a dollar, quote it :). Yes, you CAN learn the specific cases where you don't have to - but it's almost always harmless to quote them in cases where you don't have to, so you may as well just quote your variables everywhere!
– Muzer
Jun 3 at 10:15
2
2
@slebetman: And for the rest of us without this instinct,
shellcheck
will do the complaining ( shellcheck.net ).– Piskvor
Jun 3 at 12:42
@slebetman: And for the rest of us without this instinct,
shellcheck
will do the complaining ( shellcheck.net ).– Piskvor
Jun 3 at 12:42
3
3
@Roel many decades ago, I learned -- the hard way -- that 99.99999% of the time it's your fault, not a bug in the compiler or interpreter... :)
– RonJohn
Jun 3 at 14:56
@Roel many decades ago, I learned -- the hard way -- that 99.99999% of the time it's your fault, not a bug in the compiler or interpreter... :)
– RonJohn
Jun 3 at 14:56
|
show 1 more comment
2
General procedure when finding bugs in Unix: 1) Check out Single Unix Specification online for relevant definitions and rationales. 2) Submit a bugreport to austingroupbugs.net 3) Submit bugreport to the developer (with a patch if possible).
– DannyNiu
Jun 3 at 1:10
3
@DannyNiu: Your comment is not very practical. Documents like POSIX and the Single Unix Specification do not consist of millions and millions of examples; they contain explanations (with, maybe, a few examples). Those documents are of little help to somebody who doesn’t understand what is happening and why; reading them is like learning to drive by reading a roadmap. And this question isn’t asking what to do. If you want to post a question, “What should I do if I’ve found a bug in a widely used software product?”, and post an answer, go ahead.
– G-Man
Jun 3 at 4:26
@G-Man I did find DannyNiu's answer helpful in terms of the information provided, "just in case".
– Roel
Jun 3 at 4:28