#!/bin/bash
ls /root/aaa
if [ $? = 0 ];then
echo "then"
else
echo "else"
fi
个人解析:
上一条“ls /root/aaa”命令执行成功,则为真,执行echo "then"
“$?”上一条命令的结果
随便的扩展:同步文件脚本,判断同步命令是否成功,再后续执行then/else
#!/bin/bash
ls /root/aaa
if [ $? = 0 ];then
echo "then"
else
echo "else"
fi
个人解析:
上一条“ls /root/aaa”命令执行成功,则为真,执行echo "then"
“$?”上一条命令的结果
随便的扩展:同步文件脚本,判断同步命令是否成功,再后续执行then/else