Linux 下shell中if分支结构
来源:互联网 发布:对虚拟网络的看法 编辑:程序博客网 时间:2024/05/21 19:42
if 语句
if 语句的结构如下:
单分支结构
if condition
then
statement1
statement2
..........
fi
双分支结构
if condition
then
statement1
statement2
..........
else
statement3
..........
fi
多分支结构
if condition1
then
statement1
statement2
..........
elif condition2
then
statement3
statement4
..........
elif condition3
then
statement5
statement6
..........
fi
多分支结构
if condition1
then
statement1
statement2
..........
elif condition2
then
statement3
statement4
..........
elif condition3
then
statement5
statement6
..........
else
statement7
..........
fi
if 语句使用举例
下面举几个使用 if 语句的例子:
例1:
#!/bin/bash
# filename: areyouok.sh
echo "Are you OK ?"
read answer
# 在 if 的条件判断部分使用扩展的 test 语句 [[...]]
# [[]] 中可以使用正则表达式进行条件匹配
if [[ $answer == [Yy]* || $answer == [Mm]aybe ]]
then
echo "Glad to hear it."
fi
例2:
#!/bin/bash
# filename: myssh.sh
# 在条件测试中判断位置参数的个数 $#
if [ "$#" -eq "2" ]; then
ssh $1@$2
else
echo "Usage: $0 <username> <FQDN or IPAdress>"
fi
- Linux 下shell中if分支结构
- linux分支结构if
- SHELL脚本分支结构之if
- Linux 下的 shell 编程之 if-else选择结构
- 认识分支结构if
- linux下shell中if的相关参数
- linux下shell中if的相关参数
- linux下shell中if的相关参数
- Linux下Shell中if的相关参数
- Linux下Shell中if的相关参数
- linux 下shell中if的“-e,-d,-f”是什么意思
- linux 下shell中if的“-e,-d,-f”是什么意思
- linux 下shell中if的“-e,-d,-f”是什么意思
- linux 下shell中if的“-e,-d,-f”是什么意思
- linux 下shell中if的“-e,-d,-f”是什么意思
- linux 下shell中if的“-e,-d,-f”是什么意思
- linux 下shell中if的“-e,-d,-f”是什么意思
- linux shell中 if else
- AlarmManager 基本使用
- 从mediaReceiver到mediaScanner的扫描过程
- Windows7下PHP开发环境安装配置图文方
- android 几种 layout xml 属性
- 分享9条经典的编程语录
- Linux 下shell中if分支结构
- android联系人批量删除优化时间
- 文件的打开标志 和 文件的访问权限 关系
- Inno Setup使用技巧
- 验证码!
- VC中备份MYSQL数据库
- 整型数值转换为枚举
- 为View添加手势
- toSharedViewController 与toViewController 以及toModalViewController