profile
viewpoint

Ask questionsBad Advice on Replacing "which" with "command -v" - Not Equivalent

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:

Screenshot from 2019-09-28 12-28-30

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 vs which 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.

koalaman/shellcheck

Answer questions awgeorge

See also: #1162

useful!

Related questions

SC1090/SC1091: sourcing should find files relative to script hot 1
SC2181 suggests to check exit code directly when I check for several possible values hot 1
source:https://uonfu.com/
Github User Rank List