-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
builtin-type-bash.test.sh
326 lines (276 loc) · 4.6 KB
/
builtin-type-bash.test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
## oils_failures_allowed: 0
## compare_shells: bash
#### type -t -> function
f() { echo hi; }
type -t f
## stdout: function
#### type -t -> alias
shopt -s expand_aliases
alias foo=bar
type -t foo
## stdout: alias
#### type -t -> builtin
type -t echo read : [ declare local
## STDOUT:
builtin
builtin
builtin
builtin
builtin
builtin
## END
#### type -t -> keyword
type -t for time ! fi do {
## STDOUT:
keyword
keyword
keyword
keyword
keyword
keyword
## END
#### type -t control flow
# this differs from bash, but don't lie!
type -t break continue return exit
## STDOUT:
keyword
keyword
keyword
keyword
## END
## OK bash STDOUT:
builtin
builtin
builtin
builtin
## END
#### type -t -> file
type -t find xargs
## STDOUT:
file
file
## END
#### type -t doesn't find non-executable (like command -v)
PATH="$TMP:$PATH"
touch $TMP/non-executable
type -t non-executable
## STDOUT:
## END
## status: 1
## BUG bash STDOUT:
file
## END
## BUG bash status: 0
#### type -t -> not found
type -t echo ZZZ find ==
echo status=$?
## STDOUT:
builtin
file
status=1
## END
## STDERR:
## END
#### type -p and -P builtin -> file
touch /tmp/{mv,tar,grep}
chmod +x /tmp/{mv,tar,grep}
PATH=/tmp:$PATH
type -p mv tar grep
echo --
type -P mv tar grep
## STDOUT:
/tmp/mv
/tmp/tar
/tmp/grep
--
/tmp/mv
/tmp/tar
/tmp/grep
## END
#### type -a -P gives multiple files
touch _tmp/pwd
chmod +x _tmp/pwd
PATH="_tmp:/bin"
type -a -P pwd
## STDOUT:
_tmp/pwd
/bin/pwd
## END
#### type -p builtin -> not found
type -p FOO BAR NOT_FOUND
## status: 1
## STDOUT:
## END
#### type -p builtin -> not a file
type -p cd type builtin command
## STDOUT:
## END
#### type -P builtin -> not found
type -P FOO BAR NOT_FOUND
## status: 1
## STDOUT:
## END
#### type -P builtin -> not a file
type -P cd type builtin command
## status: 1
## STDOUT:
## END
#### type -P builtin -> not a file but file found
touch _tmp/{mv,tar,grep}
chmod +x _tmp/{mv,tar,grep}
PATH=_tmp:$PATH
mv () { ls; }
tar () { ls; }
grep () { ls; }
type -P mv tar grep cd builtin command type
## status: 1
## STDOUT:
_tmp/mv
_tmp/tar
_tmp/grep
## END
#### type -f builtin -> not found
type -f FOO BAR NOT FOUND
## status: 1
#### type -f builtin -> function and file exists
touch /tmp/{mv,tar,grep}
chmod +x /tmp/{mv,tar,grep}
PATH=/tmp:$PATH
mv () { ls; }
tar () { ls; }
grep () { ls; }
type -f mv tar grep
## STDOUT:
mv is /tmp/mv
tar is /tmp/tar
grep is /tmp/grep
## END
#### type -a -> function; prints shell source code
f () { :; }
type -a f
## STDOUT:
f is a function
f ()
{
:
}
## END
## OK osh STDOUT:
f is a shell function
## END
#### type -ap -> function
f () { :; }
type -ap f
## STDOUT:
## END
#### type -a -> alias; prints alias definition
shopt -s expand_aliases
alias ll="ls -lha"
type -a ll
## stdout: ll is an alias for "ls -lha"
## OK bash stdout: ll is aliased to `ls -lha'
#### type -ap -> alias
shopt -s expand_aliases
alias ll="ls -lha"
type -ap ll
## STDOUT:
## END
#### type -a -> builtin
type -a cd
## stdout: cd is a shell builtin
#### type -ap -> builtin
type -ap cd
## STDOUT:
## END
#### type -a -> keyword
type -a while
## stdout: while is a shell keyword
#### type -a -> file
touch _tmp/date
chmod +x _tmp/date
PATH=/bin:_tmp # control output
type -a date
## STDOUT:
date is /bin/date
date is _tmp/date
## END
#### type -ap -> file; abbreviated
touch _tmp/date
chmod +x _tmp/date
PATH=/bin:_tmp # control output
type -ap date
## STDOUT:
/bin/date
_tmp/date
## END
#### type -a -> builtin and file
touch _tmp/pwd
chmod +x _tmp/pwd
PATH=/bin:_tmp # control output
type -a pwd
## STDOUT:
pwd is a shell builtin
pwd is /bin/pwd
pwd is _tmp/pwd
## END
#### type -a -> builtin and file and shell function
touch _tmp/pwd
chmod +x _tmp/pwd
PATH=/bin:_tmp # control output
type -a pwd
echo ---
pwd() { echo function-too; }
type -a pwd
echo ---
type -a -f pwd
## STDOUT:
pwd is a shell builtin
pwd is /bin/pwd
pwd is _tmp/pwd
---
pwd is a function
pwd ()
{
echo function-too
}
pwd is a shell builtin
pwd is /bin/pwd
pwd is _tmp/pwd
---
pwd is a shell builtin
pwd is /bin/pwd
pwd is _tmp/pwd
## END
## OK osh STDOUT:
pwd is a shell builtin
pwd is /bin/pwd
pwd is _tmp/pwd
---
pwd is a shell function
pwd is a shell builtin
pwd is /bin/pwd
pwd is _tmp/pwd
---
pwd is a shell builtin
pwd is /bin/pwd
pwd is _tmp/pwd
## END
#### type -ap -> builtin and file; doesn't print builtin or function
touch _tmp/pwd
chmod +x _tmp/pwd
PATH=/bin:_tmp # control output
# Function is also ignored
pwd() { echo function-too; }
type -ap pwd
echo ---
type -p pwd
## STDOUT:
/bin/pwd
_tmp/pwd
---
## END
#### type -a -> executable not in PATH
touch _tmp/executable
chmod +x _tmp/executable
type -a executable
## status: 1