Chinaunix首页 | 论坛 | 博客
  • 博客访问: 898841
  • 博文数量: 453
  • 博客积分: 7865
  • 博客等级: 少将
  • 技术积分: 5673
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-29 16:21
个人简介

时光荏苒..

文章分类
文章存档

2015年(46)

2014年(22)

2013年(68)

2012年(218)

2011年(99)

分类: Python/Ruby

2011-11-21 16:55:23

test命令的语法格式:
  test expression
  或者
  [expression]

判断文件:

b c d e f g h k。。。

-b     块文件

-c     字符文件

-d     目录

-e     文件或目录

-f    

判断字符

-eq   等于

-ne   不等于

-gt   大于

-lt   小于

 

-le   小于等于

-ge   大于等于

-z    空串

=    两个字符相等

!=    两个字符不等

-n    非空串

        

filename1 -nt filename2   1比2新     (new time)

          -ot              旧

字符串比较 运算符

-z string       字符串长度为零      [ -z $myvar ]    

-n string

 

(1)判断字符串 

  -----------------------------------------
  Str1 = str2 | 当str1与str2相同时,返回True
  Str1! = str2| 当str1与str2不同时,返回True
     Str      | 当str不是空字符时,返回True
    -n str    | 当str的长度大于0时,返回True
    -z str    | 当str的长度是0时,返回True
  -----------------------------------------
 (2)整数操作符  

  ---------------------------------------------
  Int1 -eq int2|当int1等于int2时,返回True
  Int1 -ge int2|当int1大于/等于int2时,返回True
  Int1 -le int2|当int1小于/等于int2时,返回True
  Int1 -gt int2|当int1大于int2时,返回True
  Int1 -ne int2|当int1不等于int2时,返回True
  -----------------------------------------
 (3)用于文件操作的操作符,他们能检查:文件是否存在,文件类型等
  test表达式   |    含义
  ------------------------------------------------
  -d file      |当file是一个目录时,返回 True
  -f file      |当file是一个普通文件时,返回 True
  -r file      |当file是一个刻读文件时,返回 True
  -s file      |当file文件长度大于0时,返回 True
  -w file      |当file是一个可写文件时,返回 True
  -x file      |当file是一个可执行文件时,返回 True
  ------------------------------------------------
 (4)shell的逻辑操作符用于修饰/连接包含整数,字符串,文件操作符的表达式
  test表达式    |    含义
  ----------------------------------------------------------
  ! expr        |当expr的值是False时,返回True
  Expr1 -a expr2|当expr1,expr2值同为True时,返回True
  Expr1 -o expr2|当expr1,expr2的值至少有一个为True时,返回True
  -----------------------------------------------------------
注意:
tcsh shell 不使用test命令,但是tcsh中的表达式同样能承担相同的功能.tcsh
支持的表达式于C中的表达式相同.通常使用在if和while命令中.
  tcsh表达式    |    含义
  -------------------------------------------------------
  Int1 <= int2  |当int1小于/等于int2时,返回True
  Int1 >= int2  |当int1大于/等于int2时,返回True
  Int1 < int2   |当int1小于int2时,返回True
  Int1 > int2   |当int1大于int2时,返回True
  Str1 == str2  |当str1与str2相同时,返回True
  Str1 != str2  |当str1与str2不同时,返回True
  -r file       |当file是一个可读文件时,返回True
  -w file       |当file是一个可写文件时,返回True
  -x file       |当file是一个可执行文件时,返回True
  -e file       |当file存在时,返回True
  -o file       |当file文件的所有者是当前用户时,返回True
  -z file       |当file长度为0时,返回True
  -f file       |当file是一个普通文件时,返回True
  -d file       |当file是一个目录时,返回True
  Exp1 || exp2  |当exp1和exp2的值至少一个为True时,返回True
  Exp1 && exp2  |当exp1和exp2的值同为True时,返回True
  ! exp         |当exp的值为False时,返回True
  -------------------------------------------------------

内容转自:

阅读(1623) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~