【shell】Linux上判断一个命令是否存在

【Q】今天在看Shell脚本   if command -v python2 >/dev/null 2>&1

  其中 2>&1的用法很常见,是指将前面指令运行的所有输出都放到/dev/null中,  但是command -v python2的是什么意思呢?

【A】用来检查python2这个program是否存在。



参考


shell判断一个命令是否存在

https://www.cnblogs.com/tuzkee/p/3755230.html


How can I check if a program exists from a Bash script?

https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script/677212#677212


shell中如何判断某一命令是否存在

https://segmentfault.com/q/1010000000156870

http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script

https://www.cnblogs.com/embedded-linux/p/6206064.html

你可能感兴趣的:(【shell】Linux上判断一个命令是否存在)