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 break continue
31 ## STDOUT:
32 builtin
33 builtin
34 builtin
35 builtin
36 builtin
37 builtin
38 builtin
39 builtin
40 ## END
41
42 #### type -t -> keyword
43 type -t for time ! fi do {
44 ## STDOUT:
45 keyword
46 keyword
47 keyword
48 keyword
49 keyword
50 keyword
51 ## END
52
53 #### type -t -> file
54 type -t find xargs
55 ## STDOUT:
56 file
57 file
58 ## END
59
60 #### type -t doesn't find non-executable (like command -v)
61 PATH="$TMP:$PATH"
62 touch $TMP/non-executable
63 type -t non-executable
64 ## stdout-json: ""
65 ## status: 1
66 ## BUG bash STDOUT:
67 file
68 ## END
69 ## BUG bash status: 0
70
71 #### type -t -> not found
72 type -t echo ZZZ find =
73 echo status=$?
74 ## STDOUT:
75 builtin
76 file
77 status=1
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