4 ms·
"command -v" isn't reliable because several shells (including Dash) don't obey the POSIX standard. See https://github.com/oilshell/oil/blob/8fbc09bb3254cee944b0
by anonydsfsfs 5y ago
"command -v" isn't reliable because several shells (including Dash) don't obey the POSIX standard. See https://github.com/oilshell/oil/blob/8fbc09bb3254cee944b0450f640e268c2f627bec/spec/builtins2.test.sh#L78 https://github.com/oilshell/oil/blob/8fbc09bb3254cee944b0450...
- detuur 5y agoThen that's too bad for anyone who tries to use non-standard shells. It's one thing to violate a vague, rarely used standard. It's quite another to violate what is most likely the most broadly supported standard on *nix systems.
- anonydsfsfs 5y agoDash is Debian's default non-interactive shell, and it isn't POSIX compliant. The only way to get POSIX compliance on Debian is to switch to a different shell (e.g. bash).
- lucb1e 5y agoI checked your link but I don't quite get it. Is status=0 supposed to be a check rather than an assignment? Either way, it doesn't have that behavior like that for me on Debian: it behaves the same as bash. This is in dash: $ command -v whoami /usr/bin/whoami $ echo $? 0 $ command -v echo echo $ echo $? 0 $ command -v nonexistent $ echo $? 127 So that is with both a proper command (whoami), a shell built-in (echo), and neither (nonexistent). It's all as I would expect from a shell. Bash does exactly the same, although dash chooses 127 as exit status and bash chooses 1 but they're both nonzero (thus error statuses).