shell笔记
if ! hash some_exec 2>/dev/null;then
echo "'some_exec' was not found in PATH"
fi
if ! type some_exec >/dev/null;then
echo "'some_exec' was not found in PATH"
fi
不使用which ,which不是内建命令,可能不同的平台实现不一样。
2. 检测元素是否在数组里
arr=(apple,banana,orange)
exist=0
for i in $arr;do
if [[ $i == "orange"]];then
exist=1
fi
done
if [[ $exist == "1"]];then
echo "exist"
fi

浙公网安备 33010602011771号