Skip to main content
Tweeted twitter.com/#!/StackUnix/status/216207617851265024
formatting mostly
Source Link
George M
  • 14.3k
  • 4
  • 45
  • 53

Rule for invoking subshell in BASHBash?

I seem to misunderstand the BASHBash 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 Snippet A (below), the second sleepsleep command does not run in a separate shell (as determined by pstreepstree in another terminal). However, in Code Snippet B, the second sleepsleep command does run in a separate shell. The only difference between the snippets is that the second snippet has two commands within the parentheses.

Could somebody please explain the rule for when subshells are created?

CODE SNIPPET A:

sleep 5
(
sleep 5
)

CODE SNIPPET B:

sleep 5
(
x=1
sleep 5
)

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 Snippet A (below), the second sleep command does not run in a separate shell (as determined by pstree in another terminal). However, in Code Snippet B, the second sleep command does run in a separate shell. The only difference between the snippets is that the second snippet has two commands within the parentheses.

Could somebody please explain the rule for when subshells are created?

CODE SNIPPET A:

sleep 5
(
sleep 5
)

CODE SNIPPET B:

sleep 5
(
x=1
sleep 5
)

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 Snippet A (below), the second sleep command does not run in a separate shell (as determined by pstree in another terminal). However, in Code Snippet B, the second sleep command does run in a separate shell. The only difference between the snippets is that the second snippet has two commands within the parentheses.

Could somebody please explain the rule for when subshells are created?

CODE SNIPPET A:

sleep 5
(
sleep 5
)

CODE SNIPPET B:

sleep 5
(
x=1
sleep 5
)
deleted 4 characters in body
Source Link
bashful
  • 345
  • 1
  • 3
  • 5

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 Snippet A (below), the second sleep command does not run in a separate processshell (as determined by pstree in another terminal). However, in Code Snippet B, the second sleep command does run in a separate processshell. The only difference between the snippets is that the second snippet has two commands within the parentheses.

Could somebody please explain the rule for when subshells are created?

CODE SNIPPET A:

sleep 5
(
sleep 5
)

CODE SNIPPET B:

sleep 5
(
x=1
sleep 5
)

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 Snippet A (below), the second sleep command does not run in a separate process (as determined by pstree in another terminal). However, in Code Snippet B, the second sleep command does run in a separate process. The only difference between the snippets is that the second snippet has two commands within the parentheses.

Could somebody please explain the rule for when subshells are created?

CODE SNIPPET A:

sleep 5
(
sleep 5
)

CODE SNIPPET B:

sleep 5
(
x=1
sleep 5
)

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 Snippet A (below), the second sleep command does not run in a separate shell (as determined by pstree in another terminal). However, in Code Snippet B, the second sleep command does run in a separate shell. The only difference between the snippets is that the second snippet has two commands within the parentheses.

Could somebody please explain the rule for when subshells are created?

CODE SNIPPET A:

sleep 5
(
sleep 5
)

CODE SNIPPET B:

sleep 5
(
x=1
sleep 5
)
Source Link
bashful
  • 345
  • 1
  • 3
  • 5

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 Snippet A (below), the second sleep command does not run in a separate process (as determined by pstree in another terminal). However, in Code Snippet B, the second sleep command does run in a separate process. The only difference between the snippets is that the second snippet has two commands within the parentheses.

Could somebody please explain the rule for when subshells are created?

CODE SNIPPET A:

sleep 5
(
sleep 5
)

CODE SNIPPET B:

sleep 5
(
x=1
sleep 5
)