1 |
#!/bin/bash |
2 |
# |
3 |
# For testing the Python sketch |
4 |
|
5 |
### builtin |
6 |
echo hi |
7 |
# stdout: hi |
8 |
|
9 |
### command sub |
10 |
echo $(expr 3) |
11 |
# stdout: 3 |
12 |
|
13 |
### command sub with builtin |
14 |
echo $(echo hi) |
15 |
# stdout: hi |
16 |
|
17 |
### pipeline |
18 |
hostname | wc -l |
19 |
# stdout: 1 |
20 |
|
21 |
### pipeline with builtin |
22 |
echo hi | wc -l |
23 |
# stdout: 1 |
24 |
|
25 |
### here doc with var |
26 |
v=one |
27 |
tac <<EOF |
28 |
$v |
29 |
"two |
30 |
EOF |
31 |
# stdout-json: "\"two\none\n" |
32 |
|
33 |
### here doc without var |
34 |
tac <<"EOF" |
35 |
$v |
36 |
"two |
37 |
EOF |
38 |
# stdout-json: "\"two\n$v\n" |
39 |
|
40 |
### here doc with builtin |
41 |
read var <<EOF |
42 |
value |
43 |
EOF |
44 |
echo "var = $var" |
45 |
# stdout: var = value |
46 |
|
47 |
### Redirect |
48 |
expr 3 > _tmp/expr3.txt |
49 |
cat _tmp/expr3.txt |
50 |
# stdout: 3 |
51 |
# stderr-json: "" |
52 |
|
53 |
### Redirect with builtin |
54 |
echo hi > _tmp/hi.txt |
55 |
cat _tmp/hi.txt |
56 |
# stdout: hi |
57 |
|
58 |
### Here doc with redirect |
59 |
cat <<EOF >_tmp/smoke1.txt |
60 |
one |
61 |
two |
62 |
EOF |
63 |
wc -c _tmp/smoke1.txt |
64 |
# stdout: 8 _tmp/smoke1.txt |
65 |
|
66 |
### Eval |
67 |
eval "a=3" |
68 |
echo $a |
69 |
# stdout: 3 |
70 |
|
71 |
### "$@" "$*" |
72 |
func () { |
73 |
argv.py "$@" "$*" |
74 |
} |
75 |
func "a b" "c d" |
76 |
# stdout: ['a b', 'c d', 'a b c d'] |
77 |
|
78 |
### $@ $* |
79 |
func() { |
80 |
argv.py $@ $* |
81 |
} |
82 |
func "a b" "c d" |
83 |
# stdout: ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'] |
84 |
|
85 |
### failed command |
86 |
ls /nonexistent |
87 |
# status: 2 |
88 |
|
89 |
### subshell |
90 |
(echo 1; echo 2) |
91 |
# stdout-json: "1\n2\n" |
92 |
# status: 0 |
93 |
|
94 |
### for loop |
95 |
for i in a b c |
96 |
do |
97 |
echo $i |
98 |
done |
99 |
# stdout-json: "a\nb\nc\n" |
100 |
# status: 0 |
101 |
|
102 |
### vars |
103 |
a=5 |
104 |
echo $a ${a} "$a ${a}" |
105 |
# stdout: 5 5 5 5 |