20

我意识到这可能是一个愚蠢的问题,但我安装了 Centos-7 最小服务器,并且“哪个”命令不存在或丢失。我有一个需要它的脚本,但我找不到安装它的 yum 包。代码如下,来自 make 文件。

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

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

任何帮助将不胜感激......这对谷歌来说即使不是不可能也很困难

4

2 回答 2

30

要在 CentOS 中查找软件包,请使用 yum whatprovides

yum whatprovides *bin/which

在这种特殊情况下,包被称为which,所以

yum install which

应该把它拉进去。

于 2015-01-07T08:49:15.713 回答
7

which 您可以使用命令代替type命令。

type grep > /dev/null 2> /dev/null
if test "$?" != "0"
then
    echo "\"grep\" command not found."
    echo "Installation is aborted."
    exit 1
fi
于 2015-01-07T08:58:19.357 回答