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