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-json: "echo\n0\nmyfunc\n0\n1\nfor\n0\n"
14 # OK dash stdout-json: "echo\n0\nmyfunc\n0\n127\nfor\n0\n"
15
16 ### command -v with multiple names
17 # bash chooses to swallow the error! We agree with zsh if ANY word lookup
18 # fails, then the whole thing fails.
19 # All four shells behave differently here!
20 myfunc() { echo x; }
21 command -v echo myfunc ZZZ for
22 echo status=$?
23 # stdout-json: "echo\nmyfunc\nfor\nstatus=1\n"
24 # BUG bash stdout-json: "echo\nmyfunc\nfor\nstatus=0\n"
25 # BUG dash stdout-json: "echo\nstatus=0\n"
26 # OK mksh stdout-json: "echo\nmyfunc\nstatus=1\n"
27
28 ### dirs builtin
29 cd /
30 dirs
31 # stdout-json: "/\n"
32 # status: 0
33 # N-I dash/mksh status: 127
34 # N-I dash/mksh stdout-json: ""
35
36 ### dirs -c to clear the stack
37 cd /
38 pushd /tmp >/dev/null # zsh pushd doesn't print anything, but bash does
39 dirs
40 dirs -c
41 dirs
42 # stdout-json: "/tmp /\n/tmp\n"
43 # status: 0
44 # N-I dash/mksh status: 127
45 # N-I dash/mksh stdout-json: ""
46
47 ### dirs -v to print numbered stack, one entry per line
48 cd /
49 pushd /tmp >/dev/null
50 dirs -v
51 pushd /lib >/dev/null
52 dirs -v
53 # stdout-json: " 0 /tmp\n 1 /\n 0 /lib\n 1 /tmp\n 2 /\n"
54 # status: 0
55 # zsh uses tabs
56 # OK zsh stdout-json: "0\t/tmp\n1\t/\n0\t/lib\n1\t/tmp\n2\t/\n"
57 # N-I dash/mksh status: 127
58 # N-I dash/mksh stdout-json: ""
59
60 ### dirs -p to print one entry per line
61 cd /
62 pushd /tmp >/dev/null
63 dirs -p
64 pushd /lib >/dev/null
65 dirs -p
66 # stdout-json: "/tmp\n/\n/lib\n/tmp\n/\n"
67 # N-I dash/mksh status: 127
68 # N-I dash/mksh stdout-json: ""