Understanding the limits of bash token substitutionHelp understanding the bash code?Understanding Bash's...
Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1
Names of the Six Tastes
Are wands in any sort of book going to be too much like Harry Potter?
Thawing Glaciers return to hand interaction
Is it a Munchausen Number?
Is there a need for better software for writers?
Company stopped paying my salary. What are my options?
My perfect evil overlord plan... or is it?
Why did they wait for Quill to arrive?
Narcissistic cube asks who are we?
How long can fsck take on a 30 TB volume?
What's the difference between "ricochet" and "bounce"?
Are there vaccine ingredients which may not be disclosed ("hidden", "trade secret", or similar)?
Using wilcox.test() and t.test() in R yielding different p-values
Do Monks gain the 9th level Unarmored Movement benefit when wearing armor or using a shield?
A Latin text with dependency tree
Renting a house to a graduate student in my department
Rusty Chain and back cassette – Replace or Repair?
How to handle DM constantly stealing everything from sleeping characters?
Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019
What's the "magic similar to the Knock spell" referenced in the Dungeon of the Mad Mage adventure?
Why did Missandei say this?
Is there an idiom that means "revealing a secret unintentionally"?
Employee is self-centered and affects the team negatively
Understanding the limits of bash token substitution
Help understanding the bash code?Understanding Bash's Read-a-File Command SubstitutionHow bash treats “> >()”bash - Separate “table” values into strings in arrayHow to avoid `command not found` error when re-sourcing bash configuration with a key binding?bash script not running at startupBash array using system positions limits?Log redirection happens to rotated log instead of new log getting createddollar sign inside eval string in bash“cp: target '…’ is not a directory” during while loop
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
bash has token substitution, either via the $()
syntax or via the ``
syntax, eg:
$ $(echo "echo hi")
hi
AFAIK, that works like so:
- first evaluate the inner command:
echo "echo hi"
, which outputsecho hi
- then execute the resulting string as a command
echo hi
, which produceshi
That being the case, I would have expected the following to write hi
to file /tmp/hi
$ $(echo "echo hi > /tmp/hi")
but instead, it writes nothing to any file, and outputs:
hi > /tmp/hi
What's going on here? I originally thought it might be because there are spaces in the string, but the following disconfirms that theory:
$ $(echo "echo hi bob")
hi bob
bash
add a comment |
bash has token substitution, either via the $()
syntax or via the ``
syntax, eg:
$ $(echo "echo hi")
hi
AFAIK, that works like so:
- first evaluate the inner command:
echo "echo hi"
, which outputsecho hi
- then execute the resulting string as a command
echo hi
, which produceshi
That being the case, I would have expected the following to write hi
to file /tmp/hi
$ $(echo "echo hi > /tmp/hi")
but instead, it writes nothing to any file, and outputs:
hi > /tmp/hi
What's going on here? I originally thought it might be because there are spaces in the string, but the following disconfirms that theory:
$ $(echo "echo hi bob")
hi bob
bash
add a comment |
bash has token substitution, either via the $()
syntax or via the ``
syntax, eg:
$ $(echo "echo hi")
hi
AFAIK, that works like so:
- first evaluate the inner command:
echo "echo hi"
, which outputsecho hi
- then execute the resulting string as a command
echo hi
, which produceshi
That being the case, I would have expected the following to write hi
to file /tmp/hi
$ $(echo "echo hi > /tmp/hi")
but instead, it writes nothing to any file, and outputs:
hi > /tmp/hi
What's going on here? I originally thought it might be because there are spaces in the string, but the following disconfirms that theory:
$ $(echo "echo hi bob")
hi bob
bash
bash has token substitution, either via the $()
syntax or via the ``
syntax, eg:
$ $(echo "echo hi")
hi
AFAIK, that works like so:
- first evaluate the inner command:
echo "echo hi"
, which outputsecho hi
- then execute the resulting string as a command
echo hi
, which produceshi
That being the case, I would have expected the following to write hi
to file /tmp/hi
$ $(echo "echo hi > /tmp/hi")
but instead, it writes nothing to any file, and outputs:
hi > /tmp/hi
What's going on here? I originally thought it might be because there are spaces in the string, but the following disconfirms that theory:
$ $(echo "echo hi bob")
hi bob
bash
bash
asked 17 mins ago
mulllhausenmulllhausen
95272130
95272130
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your understanding of the order of the command expansions is right, but you can't expect the re-directions >
to be expanded this way. As you can see the expansion happening, the >
is treated literally
$ $(echo "echo hi > /tmp/hi")
++ echo 'echo hi > /tmp/hi'
+ echo hi '>' /tmp/hi
hi > /tmp/hi
Unless you introduce an another level of command expansion using eval
(dangerous) or other equivalent ways, the re-directions won't work.
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f517911%2funderstanding-the-limits-of-bash-token-substitution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your understanding of the order of the command expansions is right, but you can't expect the re-directions >
to be expanded this way. As you can see the expansion happening, the >
is treated literally
$ $(echo "echo hi > /tmp/hi")
++ echo 'echo hi > /tmp/hi'
+ echo hi '>' /tmp/hi
hi > /tmp/hi
Unless you introduce an another level of command expansion using eval
(dangerous) or other equivalent ways, the re-directions won't work.
add a comment |
Your understanding of the order of the command expansions is right, but you can't expect the re-directions >
to be expanded this way. As you can see the expansion happening, the >
is treated literally
$ $(echo "echo hi > /tmp/hi")
++ echo 'echo hi > /tmp/hi'
+ echo hi '>' /tmp/hi
hi > /tmp/hi
Unless you introduce an another level of command expansion using eval
(dangerous) or other equivalent ways, the re-directions won't work.
add a comment |
Your understanding of the order of the command expansions is right, but you can't expect the re-directions >
to be expanded this way. As you can see the expansion happening, the >
is treated literally
$ $(echo "echo hi > /tmp/hi")
++ echo 'echo hi > /tmp/hi'
+ echo hi '>' /tmp/hi
hi > /tmp/hi
Unless you introduce an another level of command expansion using eval
(dangerous) or other equivalent ways, the re-directions won't work.
Your understanding of the order of the command expansions is right, but you can't expect the re-directions >
to be expanded this way. As you can see the expansion happening, the >
is treated literally
$ $(echo "echo hi > /tmp/hi")
++ echo 'echo hi > /tmp/hi'
+ echo hi '>' /tmp/hi
hi > /tmp/hi
Unless you introduce an another level of command expansion using eval
(dangerous) or other equivalent ways, the re-directions won't work.
answered 3 mins ago
InianInian
5,6701632
5,6701632
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f517911%2funderstanding-the-limits-of-bash-token-substitution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown