Linux Shell 03 条件测试
2016-03-29 23:09
489 查看
条件测试
方式一:在Bash中 test命令和[]是等价的。
test命令:
[]命令: "["后面和"]"前面有空格
方式二:(( expression )) 测试数学表达式结果
1. 常用的数学运算符:+,-,*,/,%,**(取幂),位移(<<,>>),++(自增),--(自减),& | ~(位逻辑运算),&& || !(逻辑运算)
2. (())内部变量前可以不加$,内部不需要转义大小写"<,>"符号
3. (())扩展了for, if, while测试运算, 使之支持C语言式语句,例如:
方式三
[[ expression ]] 支持字符串模式匹配
方式一:在Bash中 test命令和[]是等价的。
test命令:
if test $n1 -eq $n2 then echo "The two number are equal" fi
[]命令: "["后面和"]"前面有空格
if [ $n1 -eq $n2 ] then echo "The two number are equal" fi
方式二:(( expression )) 测试数学表达式结果
if ((n1 == n2)) then echo "The two number are equal" fi
1. 常用的数学运算符:+,-,*,/,%,**(取幂),位移(<<,>>),++(自增),--(自减),& | ~(位逻辑运算),&& || !(逻辑运算)
2. (())内部变量前可以不加$,内部不需要转义大小写"<,>"符号
3. (())扩展了for, if, while测试运算, 使之支持C语言式语句,例如:
if (( n1 != n2)); then ... fi for((i=1; i<10; i++)) do ... done i=0 while((i++<10)) do echo $i done
方式三
[[ expression ]] 支持字符串模式匹配
if [[ $user == roo* ]] then echo "hello $user" fi
相关文章推荐
- Shell与其命令语法分析
- UVa 10152 - ShellSort
- shell教程二: shell中的$
- Hbase课程02- Hbase shell命令总结
- shell教程一 :介绍
- Linux shell 脚本语法总结
- 随笔 - Terminal Bash命令
- linux--shell--iftop
- SecureCRT终端上使用spark-shell时按退格键无反应的解决方法
- 用git bash 传数据到远程出错:git push origin master 出错:error: failed to push some refs to
- shell常用命令总结
- Android 通过adb shell命令查看内存,CPU,启动时间,电量等信息
- linux学习基础之1.0---shell的常见指令
- Jenkins+SVN+Maven+Shell 实现项目一键发布
- shell脚本之exec操作文件描述符 + 示例
- 转载---Shell常用命令及特殊符号整理---->持续更新中...
- Shell逐行读取文件的4种方法
- mysql5.6.7多实例安装、配置的详细讲解分析及shell启动脚本的编写
- /bin/bash: jar: command not found
- python 调用shell命令三种方法