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