Question discussion

What is the output of the following Linux shell (bash) commands?x=1 { x=2; } (x=3) echo $x

2509Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Linux shell (bash) commands?

x=1
{ x=2; }
(x=3)
echo $x
  • A1
  • BNothing is printed
  • C3
  • D2
Correct answer: D

Explanation

Commands inside braces { } run in the current shell, so x becomes 2, whereas commands inside parentheses ( ) run in a subshell and its changes to variables are lost when it ends, so echo prints 2.

Discussion 0

Nobody has replied yet. Start the discussion!