Bash Centos7 “which” command

佐手、 提交于 2019-12-23 07:29:34

问题


I realize this might be a dumb question but I have a Centos-7 minimal server install and the "which" command does not exist or is missing. I have a script that needs it and I cannot find out what the yum package is that installs it. The code is below and is from a make file.

which grep > /dev/null 2> /dev/null

if test "$?" != "0"
then
    echo "\"grep\" command not found."
    echo "Installation is aborted."
    exit 1
fi

Any help would be appreciated... this is difficult if not impossible to google


回答1:


To find a package in CentOS, use yum whatprovides:

yum whatprovides *bin/which

In this particular case, the package is called which, so

yum install which

should pull it in.




回答2:


Instead of which command you can use type command.

type grep > /dev/null 2> /dev/null
if test "$?" != "0"
then
    echo "\"grep\" command not found."
    echo "Installation is aborted."
    exit 1
fi


来源:https://stackoverflow.com/questions/27815420/bash-centos7-which-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!