shell 的条件执行

  • Post author:
  • Post category:其他


条件测试

1.test命令:

文件属性测试

字符串测试

算术测试

语法: test EXPRESSION

[ EXPRESSION ]

在bash中还有一个` `,它是[]的提高版本。

` EXPRESSION `

[ 10 \> 9]  [[ 10 > 9]]

2. if 的语法结构

if test-commands; then consequent-commands; fi

if test-commands; then

consequent-commands

fi

if test-commands

then

consequent-commands

fi

3.if…else…fi

if []

then

else

fi

4.if…elif…else…fi

if [];then

commands

elif [];then

commands

else

commands

fi

5.case 语句

case EXPRESSION in

PATTERN1)

commands;;

PATTERN2)

commands;;

esac

转载于:https://blog.51cto.com/yezhixi/1955829


关闭菜单