asgard
asgard

Reputation: 273

Bash Centos7 "which" command

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

Upvotes: 27

Views: 27427

Answers (2)

Sriharsha Kalluru
Sriharsha Kalluru

Reputation: 1823

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

Upvotes: 12

Wintermute
Wintermute

Reputation: 44043

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.

Upvotes: 38

Related Questions