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"