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