Questions tagged [subshell]
Use where a shell is run inside a shell (nested shells)
246 questions
0 votes
2 answers
163 views
Process sed capture group with a bash function before replacement: "sh: 1: <bash function>: not found"
So, I was playing around with this answer, when I found that neither printf_stdin () { read input printf "$input" } sed "/lorem ipsum foobar/ { s/'/'\"'\"'/g s/\...
5 votes
1 answer
340 views
How to wait for subshells to finish from the outer shell?
If do this on my bash terminal: ( (sleep 0.5 && echo 'first command, second result' &); (echo 'second command, first result' &); ) then I see: second command, first result ...
4 votes
2 answers
364 views
Deferred variable expansion including in a subshell
I have a command that takes always the same initial parameters. I can create a variable to capture these parameters. Also, I need to pass the output of a subshell running the same command to the ...
4 votes
4 answers
579 views
How to wait for background commands that were executed within a subshell?
Given this code: #!/bin/bash set -euo pipefail function someFn() { local input_string="$1" echo "$input_string start" sleep 3 echo "$input_string end" } function ...
0 votes
2 answers
105 views
How to temporarily substitute the login shell for running a shell command/subprocess?
My login shell is Fish, but I would like to execute a shell command (apt install ...) as if my login shell was Bash. Is it possible to make a command/subprocess believe that my login shell is /usr/bin/...
4 votes
0 answers
114 views
Why is `fc` output different through a pipe in a subshell?
Why does echo "$(fc -l -1)" show the previous command, but echo "$(fc -l -1 | cat)" show the current command? $ testfc () { > echo "$(fc -l -1)" > echo &...
0 votes
0 answers
38 views
bash subshell execution behaves unexpectedly [duplicate]
I have a script which is supposed to fetch 2 URLs sequentially: #!/bin/bash wget_command='wget --restrict-file-names=unix https://www.example.com/{path1,path2}/' $($wget_command) echo $wget_command ...
5 votes
2 answers
363 views
Duplicate stdout to pipe into another command with named pipe in POSIX shell script function
mkfifo foo printf %s\\n bar | tee foo & tr -s '[:lower:]' '[:upper:]' <foo wait rm foo This is a working POSIX shell script of what I want to do: printf %s\\n bar is symbolic for an external ...
1 vote
0 answers
106 views
What's the logic in exiting early on failure in blocks and subshells in Bash? [duplicate]
In Bash blocks {} and subshells () the exit early doesn't work if there is an OR condition following it. Take for example set -e { echo a; false; echo b; } || echo c prints a b and set -e { echo a; ...
5 votes
1 answer
371 views
How to determine what is opening tmp files when I invoke a subshell with ksh
I'm experiencing extremely sluggishness in opening subshells (by using ` ` or $( ) command substitutions in scripts) while in ksh on some Linux servers. The same problem does not exist in sh or any ...
1 vote
0 answers
28 views
Why is the first sub-command of my remote command not executing or not affecting later sub-commands? [duplicate]
This command is a simplification of the problem I've come across: ssh grinder1h.devqa sh -c "cd /etc/ssh && pwd" This command gives an output of "/home/fetch", which is ...
3 votes
0 answers
206 views
Understanding piping to a unix domain socket in the background
I have a Debian 12 (bookworm) host where I run three VMs using QEMU / KVM. To simplify VM management, each VM has a QEMU monitor socket. These sockets are /vm/1.sock, /vm/2.sock and /vm/3.sock. Among ...
0 votes
1 answer
94 views
How to exit a shell if the subshell exit with an error [closed]
there is a script, 1.sh. 1.sh starts 1a.sh and then 1b.sh. But how to exit all scripts, how to exit 1.sh and how to not start 1b.sh if 1a.sh breaks with an error?
-2 votes
1 answer
106 views
How does bash <command-argument> work?
About bash For a new tty when is executed the echo $SHLVL command it displays 1 as expected. Now, if in the same tty is executed the bash command and later again the echo $SHLVL command it displays 2. ...
0 votes
1 answer
458 views
Is it possible to give an existing Flatpak application permission to run another Flatpak?
You can give a Flatpak permissions to access files/folders outside of its sandbox using the techniques described in this Ubuntu Stack Exchange QA. But is it possible to give an existing Flatpak ...