3 回答
TA贡献1813条经验 获得超2个赞
回答
command -v <the_command>
bash
hash <the_command> # For regular commands. Or...type <the_command> # To check built-ins and keywords
解释
whichhash, typecommand
许多操作系统都有一个 which那,那个 甚至不设置退出状态
,意思是 if which foo甚至不会在那里工作 总
报告 foo存在,即使它不存在(请注意,一些POSIX shell似乎是这样做的。) hash)。 许多操作系统 which做一些定制和邪恶的事情,比如改变输出,甚至连接到包管理器。
which
$ 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; }2>&-2>/dev/null2>&-
/bin/shtypehashhashtypecommand
bashtypehashtype-PPATHhash
gdatedate:
gnudate() {
if hash gdate 2>/dev/null; then
gdate "$@"
else
date "$@"
fi}TA贡献1817条经验 获得超14个赞
添加回答
举报
