1.命令类型
if command
then
commands_ret_0
else
commands_ret_other
fi
由于linux命令一般成功情况下返回0,失败情况下返回其他值.所以如果command返回值为0则执行commands_ret_0,返回其他值的时候执行commands_ret_other
例子:比如以下脚本可以判断文件是否存在
if command
then
commands_ret_0
else
commands_ret_other
fi
由于linux命令一般成功情况下返回0,失败情况下返回其他值.所以如果command返回值为0则执行commands_ret_0,返回其他值的时候执行commands_ret_other
例子:比如以下脚本可以判断文件是否存在
#!/bin/bash
if ls -al "$1" >/dev/null ; then
echo "file exit"
else
echo "file not exist"
fi