Timeline for Subshell and process substitution
Current License: CC BY-SA 4.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 30 at 6:43 | comment | added | The Quark | Ah yes, I had forgotten that fd's are inherited by the child processes. Thank you. | |
| Jul 30 at 6:24 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 4 characters in body |
| Jul 30 at 6:03 | comment | added | Stéphane Chazelas | @TheQuark, see if the edit makes it clearer. Commands in pipelines are run concurrently, redirections are applied for each part independently, something 3<&- only closes fd 3 for something. | |
| Jul 30 at 6:02 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 588 characters in body |
| Jul 29 at 21:59 | comment | added | The Quark | I am confused with the last line { something 3<&- | that-cmd /dev/fd/4 4<&0 <&3 3<&-; } 3<&0. Isn't fd 3 closed by something 3<&- right after being opened by { ... } 3<&0? In what order do the redirections occur in this command line? | |
| Jan 22, 2023 at 19:17 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 17 characters in body |
| May 10, 2017 at 12:49 | comment | added | Ram RS | Tried editing my previous comment, that didn't work. Anyway, it looks like which_interpreter won't work in my case. I'm going to have to package my scripts into Modulefiles and hope that the user doesn't bypass the proper usage, I guess. I could also error out on a POSIX shell, or change my script to be POSIX compliant. Hmmm. Thank you for your time, @stéphane-chazelas | |
| May 10, 2017 at 12:39 | comment | added | Ram RS | I found another of your answers very useful to my situation: unix.stackexchange.com/a/71137/135331 I'm going to see if I can incorporate that into my script. | |
| May 10, 2017 at 6:57 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 | added 107 characters in body |
| May 10, 2017 at 6:50 | comment | added | Stéphane Chazelas | @Ram, see What is the portable (POSIX) way to achieve process substitution? for instance. You'd want to stop giving your script a sh extension if it's not a sh script, and use a shebang with the correct interpreter like #! /path/to/bash -. If you want to check that the shell is bash in your script, try [ -n "$BASH_VERSION" ], and whether it's in POSIX mode with [ -o posix ]. | |
| May 10, 2017 at 1:08 | vote | accept | Ram RS | ||
| May 10, 2017 at 0:29 | comment | added | Ram RS | Now, when I use sh script.sh, it uses bash too, because that's the default shell on the HPC that I use. Is there any way I can ensure the script is invoked only using bash and not anything else? As in, can I check within the script if the script was invoked using bash script.sh or sh script.sh? | |
| May 10, 2017 at 0:27 | comment | added | Ram RS | Thank you for the detailed explanation. I have a few follow up questions/remarks. My cat/echo example is just that - a base example. My actual use case involves a python script that takes in 3 inputs, one of which is being passed at the moment as a <(...). This py script is being used within a shell script, and if I run the shell script using just its name (in which case it uses the bash interpreter), it works fine. | |
| May 9, 2017 at 21:05 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 | added 593 characters in body |
| May 9, 2017 at 20:58 | history | answered | Stéphane Chazelas | CC BY-SA 3.0 |