bash: which vs command

This question already has an answer here:

  • Check if a program exists from a Bash script 29 answers

  • Well...

    command is likely built in to your shell, and with the -v option will tell you how your shell will invoke the command specified as its option.

    which is an external binary, located at /usr/bin/which which steps through the $PATH environment variable and checks for the existence of a file.

    A reason to select the former over the latter is that it avoids a dependency on something that is outside your shell.

    The two commands do different things, and you should select the one that more closely matches your needs. For example, if command is built in to your shell, command -v command will indicate this with its output (through the non-existence of path), but which command will try to point to a file on your path, regardless of how command would be interpreted by your shell.

    链接地址: http://www.djcxy.com/p/57050.html

    上一篇: 如何检查Docker是否安装在Unix shell脚本中?

    下一篇: bash:哪个vs命令