Linked Questions
13 questions linked to/from Is a sub-shell the same thing as a child-shell
2
votes
2
answers
557
views
Isn't a subshell created when I run the `bash` command? [duplicate]
Isn't a subshell created when I run the bash command? For example, after executing bash, I cannot access the value of a non-exported variable. In this case, is the environment I switch to with the ...
4
votes
1
answer
243
views
Why does the value of BASH_SUBSHELL not change while the value of SHLVL changes? [duplicate]
The bash manual says
BASH_SUBSHELL Incremented by one within each subshell or subshell environment when the shell begins executing in that environment. The
initial value is 0.
SHLVL ...
173
votes
3
answers
194k
views
Do parentheses really put the command in a subshell?
From what I've read, putting a command in parentheses should run it in a subshell, similar to running a script. If this is true, how does it see the variable x if x isn't exported?
x=1
Running (echo ...
86
votes
3
answers
31k
views
Is $() a subshell?
I understand the subshell syntax to be (<commands...>), is $() just a subshell that you can retrieve variable values from?
Note: This applies to bash 4.4 based on different wording in their ...
33
votes
3
answers
18k
views
What is the exact difference between a "subshell" and a "child process"?
According to this and this, a subshell is started by using parenthesis (…).
( echo "Hello" )
According to this, this and this, a process is forked when the command is ended with a &
...
2
votes
1
answer
44k
views
How to execute a command inside a shell script without opening a new shell
I would like to execute commands inside a shell script and store in a variable, but it is opening a new shell which I do not want. Is there any way to correct this? Here is my script.
#!/bin/bash
V1=...
6
votes
2
answers
1k
views
Why does changing $PATH affect child shells, but changing $foo not?
$ unset foo
$ unset bar
$ echo $foo
$ echo $bar
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ foo=a
$ bar=b
$ export bar
$ echo $foo
a
$ ...
0
votes
3
answers
6k
views
Why cat command doesn't use its command environment? [duplicate]
AFAIK, cat is an external command and it forks off a new process when executed, just like sh -c or executing a script. With that said I expect cat to use its command environment as it is used by ...
0
votes
2
answers
1k
views
$! is empty when running command in bash with -c or in subshell
I am trying to get the pid of the previous command with $!, but that only works in the 'main' shell:
$ echo "test" | echo $!
4436
$
If I start a subshell, then it's empty:
$ bash
$ echo &...
1
vote
1
answer
249
views
Why doesn't history output anything in a subshell?
I just realized that history does not output anything in a subshell. I'll try to show by counting lines - first a sanity check with echo:
$ echo a | wc -l
1
... and in a subshell:
bash -c 'echo a' | ...
3
votes
2
answers
511
views
zsh assignment failed within piped function
There is simple test case
local testa=("a")
local testb=("b")
function test { testb=(${(P)1}) }
test "testa"
echo "testb="$testb
output testb=a
and
local testa=("a")
local testb=("b")
function ...
2
votes
0
answers
233
views
Is the log-in shell the parent of shells in gnome terminal?
I have somehow thought that all shells that are invoked by a terminal emulator or any other way while a user is logged in are subshells of the log-in shell. Is this correct?
If it matters, I am ...
-2
votes
2
answers
190
views
Identifying shell script's subshell number from within a script itself
I am accidentally caught in a desire to reveal the subshell number (BASH_SUBSHELL) from within the script itself, but i get subshell 0
Here is the script's line
echo "Operated from subshell: $...