1 # Bash implements type -t
2
3 #### type -t -> function
4 f() { echo hi; }
5 type -t f
6 ## stdout: function
7
8 #### type -t -> alias
9 shopt -s expand_aliases
10 alias foo=bar
11 type -t foo
12 ## stdout: alias
13
14 #### type -t -> builtin
15 type -t echo read : [ declare local break continue
16 ## STDOUT:
17 builtin
18 builtin
19 builtin
20 builtin
21 builtin
22 builtin
23 builtin
24 builtin
25 ## END
26
27 #### type -t -> keyword
28 type -t for time ! fi do {
29 ## STDOUT:
30 keyword
31 keyword
32 keyword
33 keyword
34 keyword
35 keyword
36 ## END
37
38 #### type -t -> file
39 type -t find xargs
40 ## STDOUT:
41 file
42 file
43 ## END
44
45 #### type -t doesn't find non-executable (like command -v)
46 PATH="$TMP:$PATH"
47 touch $TMP/non-executable
48 type -t non-executable
49 ## stdout-json: ""
50 ## status: 1
51 ## BUG bash STDOUT:
52 file
53 ## END
54 ## BUG bash status: 0
55
56 #### type -t -> not found
57 type -t echo ZZZ find =
58 echo status=$?
59 ## STDOUT:
60 builtin
61 file
62 status=1
63 ## END
64
65 #### help
66 help
67 help help
68 ## status: 0
69
70 #### bad help topic
71 help ZZZ 2>$TMP/err.txt
72 echo "help=$?"
73 cat $TMP/err.txt | grep -i 'no help topics' >/dev/null
74 echo "grep=$?"
75 ## STDOUT:
76 help=1
77 grep=0
78 ## END
79
80 #### type -p builtin -> file
81 type -p mv tar grep
82 ## STDOUT:
83 /bin/mv
84 /bin/tar
85 /bin/grep
86 ## END
87
88 #### type -p builtin -> not found
89 type -p FOO BAR NOT_FOUND
90 ## status: 1
91 ## stdout-json: ""
92
93 #### type -p builtin -> not a file
94 type -p cd type builtin command
95 ## stdout-json: ""
96
97 #### type -P builtin -> file
98 type -P mv tar grep
99 ## STDOUT:
100 /bin/mv
101 /bin/tar
102 /bin/grep
103 ## END
104
105 #### type -P builtin -> not found
106 type -P FOO BAR NOT_FOUND
107 ## status: 1
108 ## stdout-json: ""
109
110 #### type -P builtin -> not a file
111 type -P cd type builtin command
112 ## stdout-json: ""
113 ## status: 1
114
115 #### type -P builtin -> not a file but file found
116 mv () { ls; }
117 tar () { ls; }
118 grep () { ls; }
119 type -P mv tar grep cd builtin command type
120 ## status: 1
121 ## STDOUT:
122 /bin/mv
123 /bin/tar
124 /bin/grep
125 ## END
126
127 #### type -f builtin -> not found
128 type -f FOO BAR NOT FOUND
129 ## status: 1
130
131 #### type -f builtin -> function and file exists
132 mv () { ls; }
133 tar () { ls; }
134 grep () { ls; }
135 type -f mv tar grep
136 ## STDOUT:
137 /bin/mv is a file
138 /bin/tar is a file
139 /bin/grep is a file
140 ## OK bash STDOUT:
141 mv is /bin/mv
142 tar is /bin/tar
143 grep is /bin/grep