summaryrefslogtreecommitdiffhomepage
path: root/tests/scripts/library.sh
blob: 6d6fa465d069fefae0a2e8554bc23aa6383fe7ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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 \$?: $?"