1 #!/bin/bash
2
3 ### $?
4 echo $? # starts out as 0
5 sh -c 'exit 33'
6 echo $?
7 # stdout-json: "0\n33\n"
8 # status: 0
9
10 ### $#
11 set -- 1 2 3 4
12 echo $#
13 # stdout: 4
14 # status: 0
15
16 ### $-
17 # dash's behavior seems most sensible here?
18 $SH -o nounset -c 'echo $-'
19 # OK bash stdout: huBc
20 # OK dash stdout: u
21 # OK mksh stdout: uhc
22 # status: 0
23
24 ### $_
25 # This is bash-specific.
26 echo hi
27 echo $_
28 # stdout-json: "hi\nhi\n"
29 # N-I dash/mksh stdout-json: "hi\n\n"
30
31 ### PID $$
32 # Just test that it has decimal digits
33 echo $$ | egrep '[0-9]+'
34 # status: 0
35
36 ### Background PID $!
37 # Just test that it has decimal digits
38 sleep 0.01 &
39 echo $! | egrep '[0-9]+'
40 wait
41 # status: 0
42
43 ### $PPID
44 expr $0 : '.*/osh$' && exit 99 # Disabled because of spec-runner.sh issue
45 echo $PPID | egrep '[0-9]+'
46 # Disabled because of spec-runner.sh issue: bash sets it for osh
47 # status: 0
48
49 # NOTE: There is also $BASHPID
50
51 ### $PIPESTATUS
52 echo hi | sh -c 'cat; exit 33' | wc -l >/dev/null
53 argv.py "${PIPESTATUS[@]}"
54 # status: 0
55 # stdout: ['0', '33', '0']
56 # N-I dash stdout-json: ""
57 # N-I dash status: 2
58
59 ### $PWD
60 cd /
61 echo $PWD
62 # status: 0
63 # stdout: /
64
65 ### $RANDOM
66 expr $0 : '.*/osh$' && exit 99 # Disabled because of spec-runner.sh issue
67 echo $RANDOM | egrep '[0-9]+'
68 # status: 0
69 # N-I dash status: 1