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