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

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