-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scripts: Use bash-builtin command -v
instead of external which
#555
base: main
Are you sure you want to change the base?
Conversation
`command -v` is a bash builtin and is a standardized version of `which`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @a1346054,
I checked all four files for Bash shebang lines and they all have one (while not the most portable version) so that requirement is filled. However I'm surprised to see command -v
in the new version rather than type -P
, the reason being that if our intention is replacing which
by something that is equivalent but faster, the fact that command -v
would also recognize (and prefer) Bash functions of the requested name seems like a mis-feature. Let me demonstrate:
# command -v curl
/usr/bin/curl
# type -P curl
/usr/bin/curl
# curl() { :; }
# command -v curl
curl
# type -P curl
/usr/bin/curl
So I'd consider use of type -P
more robust a closer match. What do you think?
Best, Sebastian
PS: This is just my 2 cents and I don't have write/merge permissions in this repository.
The behavior of Additionally,
|
True, but someone could add functions right into these scripts. I'm not saying it's super likely to happen but
Our target is Bash, not POSIX. |
then someone could also do builtin type -P curl but it gets really crazy if we assume the scenario that users will edit the provided scripts in crazy ways. Wonder how to fix it if the user did something like: type() { echo "something"; };
builtin() { echo "anything"; }; |
It doesn't seem to stop there, even
I was not speaking of end users. I meant people adjusting these scripts in Git upstream over time. I think we have both made our points. I would use |
In that case, it might be of interest to note that the behavior of If some maintainer for example does: curl() { wget "$@"; }; with the intention that calling |
command -v
is a bash builtin and is a standardized version ofwhich