-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Bad Advice on Replacing "which" with "command -v" - Not Equivalent #1707
Comments
I guess that was a bad example for files. Instead, try sourcing an alias functions file from another script: s.bsh: r.bsh:
and run:
Here you can see that |
It also incorrectly suggests to use
|
See also: #1162 |
@awgeorge Thanks for the update. I'll close this duplicate - and yes, |
Duplicate of #1162. |
For bugs
Rule Id: SC2230
My shellcheck version (
shellcheck --version
or "online"): version: 0.5.0[X ] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
[ X] I tried on shellcheck.net and verified that this is still a problem on the latest commit
Here's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
SEQ_CMD="$(which seq)"||MISSING_CMDS+=("seq");declare -r SEQ_CMD
^-- SC2230: which is non-standard. Use builtin 'command -v' instead.
Here's what I wanted or expected to see:
Using
command -v
vswhich
is probably bad advice. For instance if an alias exists for a command and you issue a "which command" you will get the full path to the first version in the PATH variable found. If you issue a command -v you will get the alias if one exists. These two commands are not interchangeable.Try:
$> alias cp='_(){ ((${#}==1)) && cp -nv "${1}" "$(pwd)" || cp -nv "${1}" "${2}";};_'
now, you can see the difference:
$> which cp
/bin/cp
$> command -v cp
alias cp='(){ ((${#}==1)) && cp -nv "${1}" "$(pwd)" || cp -nv "${1}" "${2}";};'
When you are using
which
to set help set command path variables you don't want it loaded with alias declarations.The text was updated successfully, but these errors were encountered: