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 prints function source code
179 f () { echo; }
180 type -a f
181 echo
182
183 type f
184
185 ## STDOUT:
186 f is a function
187 f ()
188 {
189 echo
190 }
191
192 f is a function
193 f ()
194 {
195 echo
196 }
197 ## END
198 ## OK osh STDOUT:
199 f is a shell function
200 f () { echo; }
201
202 f is a shell function
203 f () { echo; }
204 ## END
205
206 #### type -ap -> function
207 f () { :; }
208 type -ap f
209 ## STDOUT:
210 ## END
211
212 #### type -a -> alias; prints alias definition
213 shopt -s expand_aliases
214 alias ll="ls -lha"
215 type -a ll
216 ## stdout: ll is an alias for "ls -lha"
217 ## OK bash stdout: ll is aliased to `ls -lha'
218
219 #### type -ap -> alias
220 shopt -s expand_aliases
221 alias ll="ls -lha"
222 type -ap ll
223 ## STDOUT:
224 ## END
225
226 #### type -a -> builtin
227 type -a cd
228 ## stdout: cd is a shell builtin
229
230 #### type -ap -> builtin
231 type -ap cd
232 ## STDOUT:
233 ## END
234
235 #### type -a -> keyword
236 type -a while
237 ## stdout: while is a shell keyword
238
239 #### type -a -> file
240 touch _tmp/date
241 chmod +x _tmp/date
242 PATH=/bin:_tmp # control output
243
244 type -a date
245
246 ## STDOUT:
247 date is /bin/date
248 date is _tmp/date
249 ## END
250
251 #### type -ap -> file; abbreviated
252 touch _tmp/date
253 chmod +x _tmp/date
254 PATH=/bin:_tmp # control output
255
256 type -ap date
257 ## STDOUT:
258 /bin/date
259 _tmp/date
260 ## END
261
262 #### type -a -> builtin and file
263 touch _tmp/pwd
264 chmod +x _tmp/pwd
265 PATH=/bin:_tmp # control output
266
267 type -a pwd
268 ## STDOUT:
269 pwd is a shell builtin
270 pwd is /bin/pwd
271 pwd is _tmp/pwd
272 ## END
273
274 #### type -a -> builtin and file and shell function
275 touch _tmp/pwd
276 chmod +x _tmp/pwd
277 PATH=/bin:_tmp # control output
278
279 type -a pwd
280 echo ---
281
282 pwd ()
283 {
284 echo function-too
285 }
286
287 osh-normalize() {
288 sed 's/shell function/function/'
289 }
290
291 type -a pwd | osh-normalize
292 echo ---
293
294 type -a -f pwd | osh-normalize
295
296 ## STDOUT:
297 pwd is a shell builtin
298 pwd is /bin/pwd
299 pwd is _tmp/pwd
300 ---
301 pwd is a function
302 pwd ()
303 {
304 echo function-too
305 }
306 pwd is a shell builtin
307 pwd is /bin/pwd
308 pwd is _tmp/pwd
309 ---
310 pwd is a shell builtin
311 pwd is /bin/pwd
312 pwd is _tmp/pwd
313 ## END
314
315 #### type -ap -> builtin and file; doesn't print builtin or function
316 touch _tmp/pwd
317 chmod +x _tmp/pwd
318 PATH=/bin:_tmp # control output
319
320 # Function is also ignored
321 pwd() { echo function-too; }
322
323 type -ap pwd
324 echo ---
325
326 type -p pwd
327
328 ## STDOUT:
329 /bin/pwd
330 _tmp/pwd
331 ---
332 ## END
333
334 #### type -a -> executable not in PATH
335 touch _tmp/executable
336 chmod +x _tmp/executable
337 type -a executable
338 ## status: 1