|
1.建立和运行shell程序 3.shell中引号的使用方法 (1)字符串操作符 用于计算字符串表达式 test命令 | 含义 ----------------------------------------- Str1 = str2 | 当str1与str2相同时,返回True Str1! = str2| 当str1与str2不同时,返回True Str | 当str不是空字符时,返回True -n str | 当str的长度大于0时,返回True -z str | 当str的长度是0时,返回True ----------------------------------------- (2)整数操作符具有和字符操作符类似的功能.只是他们的操作是针对整数 test表达式 | 含义 --------------------------------------------- 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 ------------------------------------------------------- |
Linux下的shell编程入门(2)
本文介绍了shell程序的基本概念,包括shell程序的创建与执行方法、shell变量的定义与使用、引号及特殊字符的处理方式,以及如何利用test命令进行条件判断。
1293

被折叠的 条评论
为什么被折叠?



