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