在shell中判断某个可执行程序是否存在
2019-07-30 本文已影响0人
菜鸟瞎编
$ command -v foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
$ type foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
$ hash foo 2>/dev/null || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
if which brew 2>/dev/null; then
echo "brew exists!"
else
echo "nope, no brew installed."
fi