Created
July 19, 2018 18:02
-
-
Save mjambon/4b3c5287f7778b9302e47a9c4396f25c to your computer and use it in GitHub Desktop.
Subshells. Is the output 00, 11, 01, or 10?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
x=0 | |
y=0 | |
read x <<EOF | |
1 | |
EOF | |
echo 1 | read y | |
echo "$x$y" |
The pipe construct creates a subshell, so y
is set in the subshell only.
$ echo 123 | (read y; echo $y)
123
but
$ y=0; echo 1 | read y; echo $y
0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The program prints
10
.