那,你看到这个第一印象是不是用which?然而答案不是它。
放个stackoverflow给出的检测命令是否存在的示例代码:

if hash gdate 2>/dev/null; then
gdate "$@"else d[......]

阅读全文