linux脚本判断是否存在命令,可以使用which。
which wget >/dev/null 2>&1
if [ $? -ne 0 ]; then
apt update
apt install -y wget
fi
如果上一条命令有正确返回,$s=0,否则$s=1。代码判断如果不等于(-ne) 0, 则安装。ps: -eq 判断相等。
linux脚本判断是否存在命令,可以使用which。
which wget >/dev/null 2>&1
if [ $? -ne 0 ]; then
apt update
apt install -y wget
fi
如果上一条命令有正确返回,$s=0,否则$s=1。代码判断如果不等于(-ne) 0, 则安装。ps: -eq 判断相等。