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