4
votes
1answer
90 views

How to make a variable from a subshell available in the parent shell

I've written a quick-and-dirty script to time some reports from a web service: BASE_URL='http://example.com/json/webservice/' FIRST=1 FINAL=10000 for report_code in $(seq 1 $FINAL); do (time -p ...
6
votes
2answers
335 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 ...
2
votes
3answers
95 views

CTRL C behavior in hierarchy of shells

First of all sorry about terminology errors, I'd try to be clear. I open a shell (like sbt or node debug from my bash). Then inside this shell, I open another one (using scala or node repl ...
8
votes
3answers
540 views

Bash subshell creation with curly braces

According to this, placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. Using ps to see this in action This is the ...
13
votes
5answers
479 views

Stateful bash function

I’d like to implement a function in Bash which increases (and returns) a count with every call. Unfortunately this seems non-trivial since I’m invoking the function inside a subshell and it ...
0
votes
1answer
105 views

How to pass a flag from one script to a function in another script

I have a script that installs a bunch of programs (homebrew, git, etc) and I have it log to stdout all the things that its doing along the way, but I want the ability to pass a flag, such as --no-log ...
2
votes
2answers
263 views

BASH and Subshells

From what I gather from the online docs, the following should spawn a subshell for the part of the command embedded with {}: $ bash -c '{ sleep 10; echo "Sleeping process", $$; } & echo $$; ' ...
6
votes
2answers
234 views

Expand subshell before executing it?

I often run commands using subshells, and sometimes would like to have the subshells expanded before I run something.. This way I could verify what I'm doing, and possibly edit what's about to happen ...
3
votes
2answers
258 views

$BASHPID And $$ differ in some cases

I'm reading "BASH pocket guide of Oreilly". It said: The process ID of the current Bash process. In some cases, this can differ from $$. Above explanation , explained $BASHPID variable. ...
1
vote
1answer
336 views

curly braces and subshell

I can't figure it out. As I read in documentaion, {} doesn't create a subshell. However, looks like that sometimes it does: $ unset T; echo "T_bfr=$T"; echo $$; { echo $$; export T=1; }; echo ...
13
votes
2answers
3k views

Rule for invoking subshell in Bash?

I seem to misunderstand the Bash rule for creating a subshell. I thought parentheses always creates a subshell, which runs as its own process. However, this doesn't seem to be the case. In Code ...
12
votes
2answers
555 views

Bash syntax highlighting of subshells

Considering the large amount of questions which turn out to be related to subshells in Bash ("Why doesn't my variable increment in this piped while read loop?"), I just thought it would be very nice ...