Bash Centos7 "which" 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27815420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:08:36  来源:igfitidea点击:

Bash Centos7 "which" command

bashcommandyumwhichcentos7

提问by asgard

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.

我意识到这可能是一个愚蠢的问题,但我安装了 Centos-7 最小服务器,并且“which”命令不存在或丢失。我有一个需要它的脚本,但我找不到安装它的 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

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

任何帮助将不胜感激......这对谷歌来说很困难,如果不是不可能的话

回答by Wintermute

To find a package in CentOS, use yum whatprovides:

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

yum whatprovides *bin/which

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

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

yum install which

should pull it in.

应该把它拉进去。

回答by Sriharsha Kalluru

Instead of whichcommand you can use typecommand.

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