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