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