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
10 case $SH in (dash|mksh|zsh) exit ;; esac
11
12 xx() { echo "${*@Q}";}; xx a b c d
13 xx() { 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:
19 a b c d
20 a 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
26 shopt -s extglob
27
28 touch abc\)d
29 echo ab+(c?d)
30
31 IFS=c ABC="c?d"
32 echo ab+($ABC)
33
34 ABC='*'
35 echo $ABC
36
37 ## STDOUT:
38 abc)d
39 ab+( ?d)
40 abc)d
41 ## END
42 ## OK mksh STDOUT:
43 abc)d
44 ab+( ?d)
45 abc)d
46 ## END
47
48 #### extglob $IFS 2
49 # http://landley.net/notes.html#17-05-2020
50
51 shopt -s extglob # required for bash, not osh
52 IFS=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
61 shopt -s extglob
62
63 touch l; echo [hello"]"
64
65 touch b
66 echo [$(echo abc)]
67
68 touch +
69 echo [+()]
70 echo [+(])
71 ## STDOUT:
72 [hello]
73 b
74 +
75 [+(])
76 ## END
77 ## BUG mksh STDOUT:
78 [hello]
79 b
80 [+()]
81 [+(])
82 ## END
83
84 #### patsub of $* - http://landley.net/notes.html#23-04-2020
85 chicken() { echo ${*/b c/ghi}; }; chicken a b c d
86 ## STDOUT:
87 a 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
96 HOME=/home/foo
97
98 echo {~,~root}/pwd
99 echo \{~,~root}/pwd
100 echo ""{~,~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
115 cat <&$abc
116 ## STDOUT:
117
118 walrus
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
124 IFS=x; X=x; eval abc=a${X}b
125
126 chicken() { for i in "${@:3:5}"; do echo =$i=; done; } ; chicken ab cd ef gh ij kl mn op qr
127
128 chicken() { 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