blob: 4e93845445b9d7304d2d3567640ce8b633e060f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
seq() { awk "BEGIN { for (i = $1; i <= $2; i++) print i }"; }
# The last stage of a pipeline runs in the shell itself.
echo a b | read x y; echo "$x $y"
n=0; printf '1\n2\n3\n' | while read v; do n=$((n+v)); done; echo $n
echo val | { read z; }; echo $z
seq 1 5 | { t=0; while read v; do t=$((t+v)); done; }; echo $t
echo x | cd /; pwd
# ... but earlier stages are still subshells.
q=1; q=2 | true; echo $q
{ w=in; echo data; } | cat; echo "[${w-unset}]"
echo "${m=assigned-in-stage}" | cat; echo "[${m-unset}]"
: "${k=assigned-in-last}" | : "${k2=last}"; echo "[${k-unset}] [${k2-unset}]"
f() { fv=set; }; echo | f; echo $fv
# A fatal error in the last stage ends that stage, not the script: ksh93
# and dash both run on. The `exit` below is the one that does not.
echo a | echo "${boom:?fatal}"
echo "after fatal: $?"
echo a | eval '('
echo "after syntax: $?"
echo skip | exit 3; echo "exit in last stage exits: no"
|