I don't understand what you're trying to do since none of your examples are correct syntax. What pipe? What is myvar supposed to contain? Could you give an example with a real command and explain what output you want to save?
And what do you have against subshells anyway? After all, foo should be in stdin. I simplified the example on purpose. Sorry, but you're pretty much stuck with using subshells, even if you don't want to use them. Each command in pipes is executed in subshells too, see stackoverflow. Yes, you can edit variables in a subshell and no, you can't assign the output if a command to a variable without a subshell.
This is what's known as an XY problem. Please edit your question and explain what you are actually trying to do. Give an example of code that reproduces your problem and we should be able to help you out.
Parckwart no, all commands in a pipeline are executed in subshells. See the "Pipelines" section in man bash. Just give us a complete example and we can help you out.
Show 6 more comments. Active Oldest Votes. Improve this answer. Without the quoting, the shell would split the value on whitespace etc.
Note that saving the output of ls in a variable is pretty useless as there is no way of safely accessing the individual filenames valid filenames can contain newlines. Add a comment. Sergiy Kolodyazhnyy 15k 8 8 gold badges 43 43 silver badges 92 92 bronze badges. Zumo de Vidrio Zumo de Vidrio 1, 10 10 silver badges 25 25 bronze badges.
Improve this answer. Community Bot 1. Bob Bob Thanks Bob, It was very detailed. But I guess the tiny bit that was missing in my code was the escaped pipe using the caret character.
But this would be helpful for future reference. If you need further explanation, asking a new question might be useful. JohannesM JohannesM 9 9 silver badges 17 17 bronze badges. Risoos Risoos 1. I don't understand how this answers the question. You seem to be answering a different question. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.
Stack Gives Back You are commenting using your Twitter account. You are commenting using your Facebook account. Notify me of new comments via email. Notify me of new posts via email.
Q's Tech Babble. Share this: Twitter Facebook. Like this: Like Loading Tags: 32bit , 64bit , x64 , x Leave a Reply Cancel reply Enter your comment here Fill in your details below or click an icon to log in:. Email required Address never made public.
0コメント