1 |
#!/bin/bash |
2 |
|
3 |
#### command -v |
4 |
myfunc() { echo x; } |
5 |
command -v echo |
6 |
echo $? |
7 |
command -v myfunc |
8 |
echo $? |
9 |
command -v nonexistent # doesn't print anything |
10 |
echo $? |
11 |
command -v for |
12 |
echo $? |
13 |
## STDOUT: |
14 |
echo |
15 |
0 |
16 |
myfunc |
17 |
0 |
18 |
1 |
19 |
for |
20 |
0 |
21 |
## OK dash STDOUT: |
22 |
echo |
23 |
0 |
24 |
myfunc |
25 |
0 |
26 |
127 |
27 |
for |
28 |
0 |
29 |
## END |
30 |
|
31 |
#### command -v with multiple names |
32 |
# ALL FOUR SHELLS behave differently here! |
33 |
# |
34 |
# bash chooses to swallow the error! We agree with zsh if ANY word lookup |
35 |
# fails, then the whole thing fails. |
36 |
|
37 |
myfunc() { echo x; } |
38 |
command -v echo myfunc ZZZ for |
39 |
echo status=$? |
40 |
|
41 |
## STDOUT: |
42 |
echo |
43 |
myfunc |
44 |
for |
45 |
status=1 |
46 |
## BUG bash STDOUT: |
47 |
echo |
48 |
myfunc |
49 |
for |
50 |
status=0 |
51 |
## BUG dash STDOUT: |
52 |
echo |
53 |
status=0 |
54 |
## OK mksh STDOUT: |
55 |
echo |
56 |
myfunc |
57 |
status=1 |
58 |
## END |
59 |
|
60 |
#### command -v doesn't find non-executable file |
61 |
# PATH resolution is different |
62 |
|
63 |
PATH="$TMP:$PATH" |
64 |
touch $TMP/non-executable $TMP/executable |
65 |
chmod +x $TMP/executable |
66 |
|
67 |
command -v non-executable | grep -o /non-executable |
68 |
echo status=$? |
69 |
|
70 |
command -v executable | grep -o /executable |
71 |
echo status=$? |
72 |
|
73 |
## STDOUT: |
74 |
status=1 |
75 |
/executable |
76 |
status=0 |
77 |
## END |
78 |
|
79 |
## BUG bash/dash STDOUT: |
80 |
/non-executable |
81 |
status=0 |
82 |
/executable |
83 |
status=0 |
84 |
## END |
85 |
|
86 |
#### command skips function lookup |
87 |
seq() { |
88 |
echo "$@" |
89 |
} |
90 |
command # no-op |
91 |
seq 3 |
92 |
command seq 3 |
93 |
# subshell shouldn't fork another process (but we don't have a good way of |
94 |
# testing it) |
95 |
( command seq 3 ) |
96 |
## STDOUT: |
97 |
3 |
98 |
1 |
99 |
2 |
100 |
3 |
101 |
1 |
102 |
2 |
103 |
3 |
104 |
## END |
105 |
|
106 |
#### command command seq 3 |
107 |
command command seq 3 |
108 |
## STDOUT: |
109 |
1 |
110 |
2 |
111 |
3 |
112 |
## END |
113 |
## N-I zsh stdout-json: "" |
114 |
## N-I zsh status: 127 |
115 |
|
116 |
#### command command -v seq |
117 |
seq() { |
118 |
echo 3 |
119 |
} |
120 |
command command -v seq |
121 |
## stdout: seq |
122 |
## N-I zsh stdout-json: "" |
123 |
## N-I zsh status: 127 |
124 |
|
125 |
#### history usage |
126 |
history |
127 |
echo status=$? |
128 |
history +5 # hm bash considers this valid |
129 |
echo status=$? |
130 |
history -5 # invalid flag |
131 |
echo status=$? |
132 |
history f |
133 |
echo status=$? |
134 |
history too many args |
135 |
echo status=$? |
136 |
## status: 0 |
137 |
## STDOUT: |
138 |
status=0 |
139 |
status=0 |
140 |
status=2 |
141 |
status=2 |
142 |
status=2 |
143 |
## END |
144 |
## OK bash STDOUT: |
145 |
status=0 |
146 |
status=0 |
147 |
status=2 |
148 |
status=1 |
149 |
status=1 |
150 |
## END |
151 |
## BUG zsh/mksh STDOUT: |
152 |
status=1 |
153 |
status=1 |
154 |
status=1 |
155 |
status=1 |
156 |
status=1 |
157 |
## END |
158 |
## N-I dash STDOUT: |
159 |
status=127 |
160 |
status=127 |
161 |
status=127 |
162 |
status=127 |
163 |
status=127 |
164 |
## END |
165 |
|
166 |
#### history -d to delete history item |
167 |
|
168 |
# TODO: Respect HISTFILE and fix this test |
169 |
|
170 |
case $SH in (dash|mksh|zsh) exit ;; esac |
171 |
|
172 |
history -d 1 |
173 |
echo status=$? |
174 |
|
175 |
# problem: default for integers is -1 |
176 |
history -d -1 |
177 |
echo status=$? |
178 |
history -d -2 |
179 |
echo status=$? |
180 |
|
181 |
## STDOUT: |
182 |
status=0 |
183 |
status=1 |
184 |
status=1 |
185 |
## END |
186 |
## N-I dash/mksh/zsh stdout-json: "" |
187 |
|
188 |
#### $(command type ls) |
189 |
type() { echo FUNCTION; } |
190 |
type |
191 |
s=$(command type echo) |
192 |
echo $s | grep builtin > /dev/null |
193 |
echo status=$? |
194 |
## STDOUT: |
195 |
FUNCTION |
196 |
status=0 |
197 |
## END |
198 |
## N-I zsh STDOUT: |
199 |
FUNCTION |
200 |
status=1 |
201 |
## END |
202 |
## N-I mksh STDOUT: |
203 |
status=1 |
204 |
## END |
205 |
|
206 |
#### builtin |
207 |
cd () { echo "hi"; } |
208 |
cd |
209 |
builtin cd / && pwd |
210 |
unset -f cd |
211 |
## STDOUT: |
212 |
hi |
213 |
/ |
214 |
## END |
215 |
## N-I dash STDOUT: |
216 |
hi |
217 |
## END |
218 |
|
219 |
#### builtin ls not found |
220 |
builtin ls |
221 |
## status: 1 |
222 |
## N-I dash status: 127 |
223 |
|
224 |
#### builtin no args |
225 |
builtin |
226 |
## status: 0 |
227 |
## N-I dash status: 127 |
228 |
|
229 |
#### builtin command echo hi |
230 |
builtin command echo hi |
231 |
## status: 0 |
232 |
## stdout: hi |
233 |
## N-I dash status: 127 |
234 |
## N-I dash stdout-json: "" |