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 ### 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 external command
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 ### "$@" "$*"
67 func () {
68 argv.py "$@" "$*"
69 }
70 func "a b" "c d"
71 # stdout: ['a b', 'c d', 'a b c d']
72
73 ### $@ $*
74 func() {
75 argv.py $@ $*
76 }
77 func "a b" "c d"
78 # stdout: ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd']
79
80 ### failed command
81 ls /nonexistent
82 # status: 2
83
84 ### subshell
85 (echo 1; echo 2)
86 # stdout-json: "1\n2\n"
87 # status: 0
88
89 ### for loop
90 for i in a b c
91 do
92 echo $i
93 done
94 # stdout-json: "a\nb\nc\n"
95 # status: 0
96
97 ### vars
98 a=5
99 echo $a ${a} "$a ${a}"
100 # stdout: 5 5 5 5