Timeline for Is it possible to perform shell command substitution without using a subshell?
Current License: CC BY-SA 4.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 28 at 12:44 | comment | added | Olivier Dulac | It may be interresting to add the use of trap to "ensure" (or at least be more sure) that the temporary directory is removed in case the program is ctrl-C'ed or other. | |
| Feb 28 at 9:21 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
added 6 characters in body
|
| Sep 27, 2022 at 9:13 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
-v needed in bash to prevent it from unsetting the tmpdir function
|
| Aug 3, 2016 at 19:55 | comment | added | Stéphane Chazelas |
@starfry, note that $OLDPWD and cd - are standard (POSIX) sh. pushd/popd are only csh/tcsh/bash/zsh/yash/fish.
|
|
| Aug 3, 2016 at 19:50 | comment | added | starfry |
well your answer was still good and pointed me in the right direction. I never knew about that shell variable OLDPWD. I must remember to one day read man bash from end-to-end !
|
|
| Aug 3, 2016 at 17:30 | comment | added | Stéphane Chazelas | @starfry, OK sorry. Let's say I was the one confused by the title of the question and didn't read the rest carefully enough. | |
| Aug 3, 2016 at 17:29 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 266 characters in body
|
| Aug 3, 2016 at 15:57 | comment | added | starfry | but I thought I had said that in my question: "popd doesn't return the popped directory (it returns the new, now current, directory) and also because it's performed in a subshell." Admittedly it returns a list, but the first in the list is the one I was referring to. | |
| Aug 3, 2016 at 15:00 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 21 characters in body
|
| Aug 3, 2016 at 14:59 | comment | added | Stéphane Chazelas |
@starfry, rmdir $(popd) causes popd to run in a sub-shell which means it won't change the current directory, but even if it did not run in a subshell, the output of popd will not be the temporary directory, it will be a space separated list of directories not including that temp dir. Which is where I'm saying you're confused.
|
|
| Aug 3, 2016 at 14:54 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 1116 characters in body
|
| Aug 3, 2016 at 14:49 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 1116 characters in body
|
| Aug 3, 2016 at 14:48 | vote | accept | starfry | ||
| Aug 3, 2016 at 14:47 | comment | added | starfry |
I understand pushd and popd to work as you describe and that they're independent of command substitution - no confusion there! However, you answered by own problem by revealing $OLDPWD. I can do popd; rmdir $OLDPWD. That;s the answer to my problem - everything else just confirms what I thought. Command substitution appears to be a way to solve it but it isn't because of the subshell and you can't do command substitution without a subshell, So thanks for revealing OLDPWD - that's exactly what I need!
|
|
| Aug 3, 2016 at 14:35 | history | answered | Stéphane Chazelas | CC BY-SA 3.0 |