Shell if else命令
2017-05-21 23:00
176 查看
Shell if else命令
概述
if语句通过关系运算符判断表达式的真假来决定执行哪个分支。if 语句
if 语句的语法if [ expr ]
then
statement to be executed if expr is true
fi
注意:
1)[ expr ] ,expr和方括号之间中是需要存在空格的,否则会有语法错误。
2) 如果expr返回true,then后边的语句将会被执行;如果返回false,则是不执行任何语句。
3)最后必须以fi来结尾闭合if。
if … else语句
if … else 语句的语法if [ expr ]
then
statement to be executed if expr is true
else
statement to be executed if expr is false
fi
如果expr返回true,则then后边的语句将会被执行,否则,将执行else后边的语句。
if … elif … else 语句
if … elif … else语句语法if [ expr ]
then
statement to be executed if expr is true
elif [ expr2 ]
then
statement to be executed if expr2 is true
else
statement to be execute if both expr and expr2 is false
fi
哪个expr的值为true,就执行哪个expr后边的语句,如果都为false,则执行最后一个else的语句。
相关文章推荐
- shell脚本编程-使用结构化命令(if/else)(转)
- Linux-Shell脚本编程-学习-5-Shell编程-使用结构化命令-if-then-else-elif
- C语言中条件编译命令(#if #else #endif)(
- shell的if else 以及大于,小于等逻辑表达式
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
- shell测试和比较函数--test、[、[[、((、和 if-then-else
- bash shell if 命令参数说明
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
- shell 中if命令详解(备查)
- C语言中条件编译命令(#if #else #endif)
- shell if 命令参数说明
- shell 脚本 if then else fi
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
- bash shell if 命令参数说明
- shell if else
- #if和#ifdef使用问题&预处理命令之条件编译(#ifdef,#else,#endif,#if等)
- Linux Bash Shell学习(九):流程控制——if/else
- shell 中的 if-elif-else 语句使用实例