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