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個贊
添加回答
舉報
