Shell学习总结之逻辑运算符及表达式
来源:互联网 发布:mysql不等于字符串 编辑:程序博客网 时间:2024/05/16 17:32
Shell学习总结之逻辑运算符及表达式
一. 运算符总结说明
1. 条件运算符
2. 逻辑运算符
3. 文件和目录的判断
4. 程序的逻辑卷标判断
5. 档案的属性判断
6.两个档案之间的判断与比较
二. 逻辑表达式+运算符举例说明
#! bin/bash# -------------------------------------------------------------------------------# 文件名: Shell学习总结之逻辑运算符及表达式.sh# 版 本: 1.0# 创建日期: 2014/02/23# 描 述: 逻辑运算符和逻辑表达式学习总结# 作 者: 毕小朋# 邮 箱: wirelessqa.me@gmail.com# 博 客: http://blog.csdn.net/wirelessqa# -------------------------------------------------------------------------------website="http://blog.csdn.net/wirelessqa"myname="bixiaopeng"echo "========= 逻辑表达式 test ========="#注意:所有字符与逻辑运算符直接用“空格”分开,不能连到一起。if test 3 -eq 3 -a 3 == 3 ;then echo "true" ;fi#当3 大于 2 或 4 大于 3 并且 bxp 不等于 bixiaopeng 或 变量website不为空时,为真if test 3 > 2 -a 4 -gt 2 -a "bxp" != "bixiaopeng" -o -n "$website" ;then echo "true"; else echo "false"; fi#判断文件是否存在if test -f "/Users/bixiaopeng/justtest.txt" ;then echo "true"; else echo "false"; fi#判断目录是否存在if test -d "/Users/bixiaopeng" ;then echo "true"; else echo "false"; fiecho "========= 逻辑表达式 [] ========="#在[] 表达式中,常见的>,<需要加转义字符,表示字符串大小比较,以acill码位置作为比较。#不直接支持<>运算符,还有逻辑运算符 || 和 && 它需要用-a[and] –o[or]表示。if [ 3 -eq 3 -a 3 == 3 ];then echo "true" ;fi#当3 大于 2 或 4 大于 3 并且 bxp 不等于 bixiaopeng 或 变量website不为空时,为真if [ 3 \> 2 -a 4 -gt 2 -a "bxp" != "bixiaopeng" -o -n "$website" ] ;then echo "true"; else echo "false"; fi#判断文件是否存在if [ -f "/Users/bixiaopeng/justtest.txt" ] ;then echo "true"; else echo "false"; fi#判断目录是否存在if [ -d "/Users/bixiaopeng" ] ;then echo "true"; else echo "false"; fiecho "========= 逻辑表达式 [[]] ========="#[[]] 运算符只是[]运算符的扩充。能够支持<,>符号运算不需要转义符,它还是以字符串比较大小。里面支持逻辑运算符 || 和 &&if [[ 3 -eq 3 && 3 == 3 ]];then echo "true" ;fi#当3 大于 2 或 4 大于 3 并且 bxp 不等于 bixiaopeng 或 变量website不为空时,为真if [[ 3 > 2 && 4 -gt 2 && "bxp" != "bixiaopeng" || -n "$website" ]] ;then echo "true"; else echo "false"; fi#判断文件是否存在if [[ -f "/Users/bixiaopeng/justtest.txt" ]] ;then echo "true"; else echo "false"; fi#判断目录是否存在if [[ -d "/Users/bixiaopeng" ]] ;then echo "true"; else echo "false"; fi#[[]] 中可以使用通配符,不需要引号[[ $myname = b*peng ]] && echo "true"
微信公众帐号: wirelessqa
关于作者:
作者: 毕小朋 | 老 毕 邮箱: wirelessqa.me@gmail.com
微博: @WirelessQA 博客: http://blog.csdn.net/wirelessqa
1 0
- Shell学习总结之逻辑运算符及表达式
- Shell学习总结之逻辑运算符及表达式
- Shell逻辑运算符及表达式
- shell 逻辑运算符、逻辑表达式
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- Shell 逻辑运算符、逻辑表达式、性能比较
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- linux shell 逻辑运算符、逻辑表达式详解
- WPF快速入门2—布局WrapPanel,DockPanel,StackPanel
- 读书摘要--Java程序设计5-6章:多态+异常
- myeclipse jsp和java字体设置
- android中的SoundPool
- 经典面试题:链表的相交与环问题
- Shell学习总结之逻辑运算符及表达式
- linux网络编程
- 类StringBuilder String StringBuffer区别及详细介绍
- 额外任务却令人绝望而难为on你呢
- [博弈]POJ 2234 Matches Game
- PATH_SEPARATOR是什么
- aix 环境下部分depinfo = xx 代表的错误号信息
- hdu1134(卡特兰数)
- 游戏核心算法编程内幕学习(一):游戏发展历史