OILS / spec / toysh.test.sh View on Github | oils.pub

140 lines, 59 significant
1# Snippets from http://landley.net/notes.html
2
3## oils_failures_allowed: 3
4## compare_shells: bash mksh
5
6#### @Q
7# http://landley.net/notes.html#24-06-2020
8
9# Fix these
10case $SH in (dash|mksh|zsh) exit ;; esac
11
12xx() { echo "${*@Q}";}; xx a b c d
13xx() { echo "${@@Q}";}; xx a b c d
14## STDOUT:
15'a' 'b' 'c' 'd'
16'a' 'b' 'c' 'd'
17## END
18## OK osh STDOUT:
19a b c d
20a b c d
21## END
22## N-I dash/mksh/zsh stdout-json: ""
23
24#### extglob $IFS 1
25# http://landley.net/notes.html#12-06-2020
26shopt -s extglob
27
28touch abc\)d
29echo ab+(c?d)
30
31IFS=c ABC="c?d"
32echo ab+($ABC)
33
34ABC='*'
35echo $ABC
36
37## STDOUT:
38abc)d
39ab+( ?d)
40abc)d
41## END
42## OK mksh STDOUT:
43abc)d
44ab+( ?d)
45abc)d
46## END
47
48#### extglob $IFS 2
49# http://landley.net/notes.html#17-05-2020
50
51shopt -s extglob # required for bash, not osh
52IFS=x; ABC=cxd; for i in +($ABC); do echo =$i=; done
53
54## STDOUT:
55=+(c=
56=d)=
57## END
58
59#### char class / extglob
60# http://landley.net/notes.html#14-05-2020
61shopt -s extglob
62
63touch l; echo [hello"]"
64
65touch b
66echo [$(echo abc)]
67
68touch +
69echo [+()]
70echo [+(])
71## STDOUT:
72[hello]
73b
74+
75[+(])
76## END
77## BUG mksh STDOUT:
78[hello]
79b
80[+()]
81[+(])
82## END
83
84#### patsub of $* - http://landley.net/notes.html#23-04-2020
85chicken() { echo ${*/b c/ghi}; }; chicken a b c d
86## STDOUT:
87a b c d
88## END
89## BUG mksh stdout-json: ""
90## BUG mksh status: 1
91
92
93#### Brace Expansion
94# http://landley.net/notes.html#04-01-2020
95
96HOME=/home/foo
97
98echo {~,~root}/pwd
99echo \{~,~root}/pwd
100echo ""{~,~root}/pwd
101
102## STDOUT:
103/home/foo/pwd /root/pwd
104{~,~root}/pwd
105~/pwd ~root/pwd
106## END
107## OK mksh STDOUT:
108~/pwd ~root/pwd
109{~,~root}/pwd
110~/pwd ~root/pwd
111## END
112
113#### {abc}<<< - http://landley.net/notes-2019.html#09-12-2019
114{ echo; } {abc}<<< walrus
115cat <&$abc
116## STDOUT:
117
118walrus
119## END
120## N-I mksh stdout-json: ""
121## N-I mksh status: 1
122
123#### slice of @ and @ - http://landley.net/notes.html#23-04-2020
124IFS=x; X=x; eval abc=a${X}b
125
126chicken() { for i in "${@:3:5}"; do echo =$i=; done; } ; chicken ab cd ef gh ij kl mn op qr
127
128chicken() { for i in "${*:3:5}"; do echo =$i=; done; } ; chicken ab cd ef gh ij kl mn op qr
129
130## STDOUT:
131=ef=
132=gh=
133=ij=
134=kl=
135=mn=
136=ef gh ij kl mn=
137## END
138## N-I mksh stdout-json: ""
139## N-I mksh status: 1
140