1 |
## oils_failures_allowed: 4
|
2 |
## compare_shells: bash
|
3 |
|
4 |
|
5 |
|
6 |
help
|
7 |
echo status=$? >&2
|
8 |
help help
|
9 |
echo status=$? >&2
|
10 |
help -- help
|
11 |
echo status=$? >&2
|
12 |
## STDERR:
|
13 |
status=0
|
14 |
status=0
|
15 |
status=0
|
16 |
## END
|
17 |
|
18 |
|
19 |
help ZZZ 2>$TMP/err.txt
|
20 |
echo "help=$?"
|
21 |
cat $TMP/err.txt | grep -i 'no help topics' >/dev/null
|
22 |
echo "grep=$?"
|
23 |
## STDOUT:
|
24 |
help=1
|
25 |
grep=0
|
26 |
## END
|
27 |
|
28 |
|
29 |
type mapfile >/dev/null 2>&1 || exit 0
|
30 |
printf '%s\n' {1..5..2} | {
|
31 |
mapfile
|
32 |
echo "n=${#MAPFILE[@]}"
|
33 |
printf '[%s]\n' "${MAPFILE[@]}"
|
34 |
}
|
35 |
## STDOUT:
|
36 |
n=3
|
37 |
[1
|
38 |
]
|
39 |
[3
|
40 |
]
|
41 |
[5
|
42 |
]
|
43 |
## END
|
44 |
## N-I dash/mksh/zsh/ash STDOUT:
|
45 |
## END
|
46 |
|
47 |
|
48 |
type readarray >/dev/null 2>&1 || exit 0
|
49 |
printf '%s\n' {1..5..2} | {
|
50 |
readarray
|
51 |
echo "n=${#MAPFILE[@]}"
|
52 |
printf '[%s]\n' "${MAPFILE[@]}"
|
53 |
}
|
54 |
## STDOUT:
|
55 |
n=3
|
56 |
[1
|
57 |
]
|
58 |
[3
|
59 |
]
|
60 |
[5
|
61 |
]
|
62 |
## END
|
63 |
## N-I dash/mksh/zsh/ash STDOUT:
|
64 |
## END
|
65 |
|
66 |
|
67 |
type mapfile >/dev/null 2>&1 || exit 0
|
68 |
printf '%s\n' {1..5..2} | {
|
69 |
mapfile arr
|
70 |
echo "n=${#arr[@]}"
|
71 |
printf '[%s]\n' "${arr[@]}"
|
72 |
}
|
73 |
## STDOUT:
|
74 |
n=3
|
75 |
[1
|
76 |
]
|
77 |
[3
|
78 |
]
|
79 |
[5
|
80 |
]
|
81 |
## END
|
82 |
## N-I dash/mksh/zsh/ash STDOUT:
|
83 |
## END
|
84 |
|
85 |
|
86 |
# Note: Bash-4.4+
|
87 |
type mapfile >/dev/null 2>&1 || exit 0
|
88 |
printf '%s:' {1..5..2} | {
|
89 |
mapfile -d : arr
|
90 |
echo "n=${#arr[@]}"
|
91 |
printf '[%s]\n' "${arr[@]}"
|
92 |
}
|
93 |
## STDOUT:
|
94 |
n=3
|
95 |
[1:]
|
96 |
[3:]
|
97 |
[5:]
|
98 |
## END
|
99 |
## N-I dash/mksh/zsh/ash STDOUT:
|
100 |
## END
|
101 |
|
102 |
|
103 |
# Note: Bash-4.4+
|
104 |
type mapfile >/dev/null 2>&1 || exit 0
|
105 |
printf '%s\0' {1..5..2} | {
|
106 |
mapfile -d '' arr
|
107 |
echo "n=${#arr[@]}"
|
108 |
printf '[%s]\n' "${arr[@]}"
|
109 |
}
|
110 |
## STDOUT:
|
111 |
n=3
|
112 |
[1]
|
113 |
[3]
|
114 |
[5]
|
115 |
## END
|
116 |
## N-I dash/mksh/zsh/ash STDOUT:
|
117 |
## END
|
118 |
|
119 |
|
120 |
type mapfile >/dev/null 2>&1 || exit 0
|
121 |
printf '%s\n' {1..5..2} | {
|
122 |
mapfile -t arr
|
123 |
echo "n=${#arr[@]}"
|
124 |
printf '[%s]\n' "${arr[@]}"
|
125 |
}
|
126 |
## STDOUT:
|
127 |
n=3
|
128 |
[1]
|
129 |
[3]
|
130 |
[5]
|
131 |
## END
|
132 |
## N-I dash/mksh/zsh/ash STDOUT:
|
133 |
## END
|
134 |
|
135 |
|
136 |
type mapfile >/dev/null 2>&1 || exit 0
|
137 |
printf '%s\r\n' {1..5..2} | {
|
138 |
mapfile -t arr
|
139 |
argv.py "${arr[@]}"
|
140 |
}
|
141 |
## STDOUT:
|
142 |
['1\r', '3\r', '5\r']
|
143 |
## END
|
144 |
## N-I dash/mksh/zsh/ash STDOUT:
|
145 |
## END
|
146 |
|
147 |
|
148 |
type mapfile >/dev/null 2>&1 || exit 0
|
149 |
printf '%s\n' a{0..2} | {
|
150 |
arr=(x y z)
|
151 |
mapfile -O 2 -t arr
|
152 |
echo "n=${#arr[@]}"
|
153 |
printf '[%s]\n' "${arr[@]}"
|
154 |
}
|
155 |
## STDOUT:
|
156 |
n=5
|
157 |
[x]
|
158 |
[y]
|
159 |
[a0]
|
160 |
[a1]
|
161 |
[a2]
|
162 |
## END
|
163 |
## N-I dash/mksh/zsh/ash STDOUT:
|
164 |
## END
|
165 |
|
166 |
|
167 |
type mapfile >/dev/null 2>&1 || exit 0
|
168 |
printf '%s\n' a{0..10} | {
|
169 |
mapfile -s 5 -n 3 -t arr
|
170 |
echo "n=${#arr[@]}"
|
171 |
printf '[%s]\n' "${arr[@]}"
|
172 |
}
|
173 |
## STDOUT:
|
174 |
n=3
|
175 |
[a5]
|
176 |
[a6]
|
177 |
[a7]
|
178 |
## END
|
179 |
## N-I dash/mksh/zsh/ash STDOUT:
|
180 |
## END
|
181 |
|
182 |
|
183 |
shopt -s lastpipe # for bash
|
184 |
|
185 |
seq 2 | mapfile m
|
186 |
seq 3 | readarray r
|
187 |
echo ${#m[@]}
|
188 |
echo ${#r[@]}
|
189 |
## STDOUT:
|
190 |
2
|
191 |
3
|
192 |
## END
|