June 2017
Beginner
502 pages
11h 26m
English
Grouping the commands into parenthesis have them executed in a subshell, and this has a subtle but outstanding implication: whatever you do in the subshell will not be reachable from the calling shell, so if you execute a subshell from a script with commands inside, what you will do in the subshell will not be available to the calling script:
#!/bin/bashx=10echo "The initial value of x is: $x"(x=$(( x*x )) ; echo "The value of x is: $x")echo "But outside the subshell the value of x is untouched: $x"
Now, let's execute the code:
zarrelli:~$ ./subshell.shThe initial value of x is: 10The value of x is: 100But outside the subshell the value of x is untouched: 10
It comes quite straightforward ...
Read now
Unlock full access