兼容POSIX的command
如果要兼容POSIX的话可以使用command
command -v <command>
示例如下:
if ! [ -x "$(command -v curl)" ]; then
echo 'Error: curl is not installed.' >&2
exit 1
fi
使用Bash的bash或type
bash环境可以使用hash
或type
命令
hash <command>
type <command>
检查wget是否存在,示例如下:
check_wget() {
if hash wget 2>/dev/null; then
wget "$@"
else
curl "$@"
fi
}

本文由 空心菜 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jul 5, 2022 at 03:55 am