Shell脚本学习 - 流程控制和函数

继续Shell的学习

流程控制

if else

流程控制不可为空,如果else没有语句执行,就不要写else

if:

if condition

then

    command1

    command2

    ...

    commandN

fi

if else:

if condition

then

    command1

    command2

    ...

    conditionN

else

    command

fi

if else-if else:

if condition1

then

    command1

elif condition2

then

    command2

else

    commandN

fi

if else语句经常和test命令结合使用

num1=$[2*3]

num2=$[1+5]

if test $[num1] -eq $[num2]

then

    echo '两个数字相等'

else

    echo '两个数字不等'

fi

for循环

未完待续

猜你喜欢

转载自www.cnblogs.com/wuhuohanke/p/10153531.html