1 |
#!/usr/bin/env 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 |
#### and-or chains |
26 |
echo 1 && echo 2 || echo 3 && echo 4 |
27 |
echo -- |
28 |
false || echo A |
29 |
false || false || echo B |
30 |
false || false || echo C && echo D || echo E |
31 |
## STDOUT: |
32 |
1 |
33 |
2 |
34 |
4 |
35 |
-- |
36 |
A |
37 |
B |
38 |
C |
39 |
D |
40 |
## END |
41 |
|
42 |
#### here doc with var |
43 |
v=one |
44 |
tac <<EOF |
45 |
$v |
46 |
"two |
47 |
EOF |
48 |
## stdout-json: "\"two\none\n" |
49 |
|
50 |
#### here doc without var |
51 |
tac <<"EOF" |
52 |
$v |
53 |
"two |
54 |
EOF |
55 |
## stdout-json: "\"two\n$v\n" |
56 |
|
57 |
#### here doc with builtin |
58 |
read var <<EOF |
59 |
value |
60 |
EOF |
61 |
echo "var = $var" |
62 |
## stdout: var = value |
63 |
|
64 |
#### Redirect external command |
65 |
expr 3 > $TMP/expr3.txt |
66 |
cat $TMP/expr3.txt |
67 |
## stdout: 3 |
68 |
## stderr-json: "" |
69 |
|
70 |
#### Redirect with builtin |
71 |
echo hi > _tmp/hi.txt |
72 |
cat _tmp/hi.txt |
73 |
## stdout: hi |
74 |
|
75 |
#### Here doc with redirect |
76 |
cat <<EOF >_tmp/smoke1.txt |
77 |
one |
78 |
two |
79 |
EOF |
80 |
wc -c _tmp/smoke1.txt |
81 |
## stdout: 8 _tmp/smoke1.txt |
82 |
|
83 |
#### "$@" "$*" |
84 |
func () { |
85 |
argv.py "$@" "$*" |
86 |
} |
87 |
func "a b" "c d" |
88 |
## stdout: ['a b', 'c d', 'a b c d'] |
89 |
|
90 |
#### $@ $* |
91 |
func() { |
92 |
argv.py $@ $* |
93 |
} |
94 |
func "a b" "c d" |
95 |
## stdout: ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'] |
96 |
|
97 |
#### failed command |
98 |
ls /nonexistent |
99 |
## status: 2 |
100 |
|
101 |
#### subshell |
102 |
(echo 1; echo 2) |
103 |
## status: 0 |
104 |
## STDOUT: |
105 |
1 |
106 |
2 |
107 |
## END |
108 |
|
109 |
#### for loop |
110 |
for i in a b c |
111 |
do |
112 |
echo $i |
113 |
done |
114 |
## status: 0 |
115 |
## STDOUT: |
116 |
a |
117 |
b |
118 |
c |
119 |
## END |
120 |
|
121 |
#### vars |
122 |
a=5 |
123 |
echo $a ${a} "$a ${a}" |
124 |
## stdout: 5 5 5 5 |