1 |
#!/bin/bash |
2 |
# |
3 |
# Test $0 $1 $2 |
4 |
|
5 |
### Normal and braced |
6 |
$SH -c 'echo $0 $1 ${2}' a b c d |
7 |
# stdout: a b c |
8 |
|
9 |
### In function |
10 |
myfunc() { |
11 |
echo $1 ${2} |
12 |
} |
13 |
myfunc a b c d |
14 |
# stdout: a b |
15 |
|
16 |
### $0 with -c |
17 |
$SH -c 'echo $0' | grep -o 'sh$' |
18 |
# stdout: sh |
19 |
|
20 |
### $0 with stdin |
21 |
echo 'echo $0' | $SH | grep -o 'sh$' |
22 |
# stdout: sh |
23 |
|
24 |
### $0 with -i |
25 |
echo 'echo $0' | $SH -i | grep -o 'sh$' |
26 |
# stdout: sh |
27 |
|
28 |
### $0 with filename |
29 |
s=_tmp/dollar0 |
30 |
echo 'echo $0' > $s |
31 |
chmod +x $s |
32 |
$SH $s |
33 |
# stdout: _tmp/dollar0 |