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 rm * # setup
26 # http://landley.net/notes.html#12-06-2020
27 shopt -s extglob
28
29 touch abc\)d
30 echo ab+(c?d)
31
32 IFS=c ABC="c?d"
33 echo ab+($ABC)
34
35 ABC='*'
36 echo $ABC
37
38 ## STDOUT:
39 abc)d
40 ab+( ?d)
41 _tmp abc)d
42 ## END
43 ## OK mksh STDOUT:
44 abc)d
45 ab+( ?d)
46 _tmp abc)d
47 ## END
48
49 #### extglob $IFS 2
50 # http://landley.net/notes.html#17-05-2020
51
52 shopt -s extglob # required for bash, not osh
53 IFS=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
62 shopt -s extglob
63
64 rm *
65
66 touch l; echo [hello"]"
67
68 touch b
69 echo [$(echo abc)]
70
71 touch +
72 echo [+()]
73 echo [+(])
74 ## STDOUT:
75 [hello]
76 b
77 +
78 [+(])
79 ## END
80 ## BUG mksh STDOUT:
81 [hello]
82 b
83 [+()]
84 [+(])
85 ## END
86
87 #### patsub of $* - http://landley.net/notes.html#23-04-2020
88 chicken() { echo ${*/b c/ghi}; }; chicken a b c d
89 ## STDOUT:
90 a 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
99 HOME=/home/foo
100
101 echo {~,~root}/pwd
102 echo \{~,~root}/pwd
103 echo ""{~,~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
118 cat <&$abc
119 ## STDOUT:
120
121 walrus
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
127 IFS=x; X=x; eval abc=a${X}b
128
129 chicken() { for i in "${@:3:5}"; do echo =$i=; done; } ; chicken ab cd ef gh ij kl mn op qr
130
131 chicken() { 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