OILS / spec / toysh.test.sh View on Github | oilshell.org

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