shell编程_流程控制_if
if-then
1 语法格式1 2 if command 3 then 4 comands 5 fi 6 7 语法格式2 8 if [ command ];then 9 comands 10 fi
#! /bin/bash if date then echo "it worked" fi #date命令执行成功,退出状态码为0,then中的echo语句就会输出。
#! /bin/bash
if asdfg
then
echo "it did not work"
fi
echo "we are outside of the if statement"
#asdfg命令无法执行,退出状态码非0,then中的echo语句无法执行。
#! /bin/bash
if [ $# != 1 ];then
echo "program argv[1]"
fi
if-then-else
if-then-else语句其语法格式如下。
if command then commands else comands fi
嵌套if
if command1
then
command set 1
elif command2
then
command set 2
elif command3
then
command set 3
elif command
then
command set4
fi
posted on 2020-12-22 21:27 XiaoXiaoli 阅读(119) 评论(0) 收藏 举报
浙公网安备 33010602011771号