# Integration: a library sourced with ".", scripts without "#!", # and exec replacing the shell. cat >lib.sh <<'LIB' LIB_LOADED=yes greet() { echo "hello, $1"; } add() { echo $(($1 + $2)); } LIB . ./lib.sh echo "$LIB_LOADED"; greet world; add 2 3 cat >noshebang <<'NS' echo "no #! line: run by the shell, args: $*" exit 6 NS chmod +x noshebang ./noshebang a b; echo "status $?" cat >withshebang <<'WS' #!/bin/sh echo "has #!: $1" WS chmod +x withshebang; ./withshebang x PATH=$PWD:$PATH; noshebang c; echo "via PATH $?" ( . ./nonexistent ) 2>/dev/null; echo "missing . file: $?" out=$( exec echo "exec in cmdsub" ); echo "$out" ( exec >/dev/null; echo hidden ); echo "exec redirection only in subshell" $TSH -c 'exec echo replaced; echo not-reached' $TSH -c 'f() { return 3; }; f; exit' ; echo "exit takes \$?: $?"