`command -v` portability
The "which" utility is not guaranteed to be installed, and if it is, its behavior is not portable.
Conversely, the "command -v" shell builtin is required to exist in all POSIX 2008 compliant shells, and is thus guaranteed to work everywhere.
Examples of open-source shells likely to be installed as /bin/sh on Linux, which implement the 12-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh.
A side benefit of using the POSIX portable option is that it does not require an external disk executable to be forked. This therefore represents a mild speedup.
Merge request reports
Activity
this is another fix of #196 (closed)
mentioned in merge request !43 (closed)
added 5 commits
Toggle commit listApparently so.
But it's not entirely clear what to do or who to ask in order to get anything merged. Hence my MR has been outstanding for a year, and is collecting duplicates.
Oh well, at least the code doesn't change often enough for gitlab's autorebase to be unable to figure out how to rebase. ;)
(Then again that itself might be worrisome.)
It is okay. I just mentioned the relevant issue number for GitLab links.
Your merge request suggests to remove redirection of stderr,
2>&1
. Is it safe? POSIX does not forbid printing diagnostic messages of the command utility. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.htmlDo we not end up with multiple useless output when trying to open something? Like
command: qwerty: not found
I have checked Bash and Dash, their command prints nothing on such an error.
On the contrary, my reading of POSIX is that it does forbid printing diagnostic messages... when using the
-v
option.Otherwise, no output shall be written and the exit status shall reflect that the name was not found.
I'm not aware of a shell that does print diagnostics on the -v option.
The other use of
command
to run a command, not print the location of the command, does print diagnostics.
Nor do ksh, zsh, mksh...
Busybox sh (actually ash) was created by importing the dash source code into the busybox git tree.
Periodically, the Busybox project imports commits of the form "Upstream commit: ..." in order to re-sync dash changes, though busybox ash has expanded the scope of the original code import (for example, it has a CONFIG_ASH_BASH_COMPAT: "bash-compatible extensions").
So they are likely to behave the same or similar. :)
mentioned in issue #196 (closed)
321 320 args=$(( $args - 1 )) 322 321 done 323 322 [ $replaced -eq 1 ] || set -- "$@" "$target" 324 "$command_exec" "$@" 323 env "$command" "$@" mentioned in merge request !60 (closed)
mentioned in merge request !52 (merged)
OK I'm woken up, but this needs to be rebased indeed, and the button to do so doesn't work. @eschwartz can you rebase this MR?
added 5 commits
Toggle commit listadded 5 commits
Toggle commit listmentioned in merge request !115 (merged)
mentioned in commit f113a8b9