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 skips function lookup |
61 |
seq() { |
62 |
echo "$@" |
63 |
} |
64 |
command # no-op |
65 |
seq 3 |
66 |
command seq 3 |
67 |
# subshell shouldn't fork another process (but we don't have a good way of |
68 |
# testing it) |
69 |
( command seq 3 ) |
70 |
## STDOUT: |
71 |
3 |
72 |
1 |
73 |
2 |
74 |
3 |
75 |
1 |
76 |
2 |
77 |
3 |
78 |
## END |
79 |
|
80 |
#### command command seq 3 |
81 |
command command seq 3 |
82 |
## STDOUT: |
83 |
1 |
84 |
2 |
85 |
3 |
86 |
## END |
87 |
## N-I zsh stdout-json: "" |
88 |
## N-I zsh status: 127 |
89 |
|
90 |
#### command command -v seq |
91 |
seq() { |
92 |
echo 3 |
93 |
} |
94 |
command command -v seq |
95 |
## stdout: seq |
96 |
## N-I zsh stdout-json: "" |
97 |
## N-I zsh status: 127 |
98 |
|
99 |
#### history usage |
100 |
history |
101 |
echo status=$? |
102 |
history +5 # hm bash considers this valid |
103 |
echo status=$? |
104 |
history -5 # invalid flag |
105 |
echo status=$? |
106 |
history f |
107 |
echo status=$? |
108 |
history too many args |
109 |
echo status=$? |
110 |
## status: 0 |
111 |
## STDOUT: |
112 |
status=0 |
113 |
status=0 |
114 |
status=2 |
115 |
status=2 |
116 |
status=2 |
117 |
## END |
118 |
## OK bash STDOUT: |
119 |
status=0 |
120 |
status=0 |
121 |
status=2 |
122 |
status=1 |
123 |
status=1 |
124 |
## END |
125 |
## BUG zsh/mksh STDOUT: |
126 |
status=1 |
127 |
status=1 |
128 |
status=1 |
129 |
status=1 |
130 |
status=1 |
131 |
## END |
132 |
## N-I dash STDOUT: |
133 |
status=127 |
134 |
status=127 |
135 |
status=127 |
136 |
status=127 |
137 |
status=127 |
138 |
## END |