在Linux环境中,`test`命令(也称为`[ ]`)是一个用于检查文件、字符串、算术表达式的条件是否为真的工具。它在shell脚本中经常被用来进行条件判断和控制流程。 ### 基础概念 `te...
若string为空字符串,则为false。 注:-n亦可省略 test str1 = str2判定str1是否等于str2,若相等,则回传true test str1 != str2判定str1是否不等于str2,若相等,则回传false 6.多重条件判定,例如:test -r filename -a -x filename -a (and)两状况同时成立!例如test -r file -a -x file,则file...
test -z $filename && echo "You need to input a filename." && exit 0 #判断文件是否存在 test ! -e $filename && echo "The filename $filename does not exist" && exit 0 #判断文件类型与属性 test -f $filename && filetype="regular file" test -d $filename && filetype="directory" te...
test 1 -gt 2 && echo "yes" || echo "no" (在屏幕上显示“no”,因为 1 不大于 2) test 1 -le 2 && echo "yes" || echo "no" (在屏幕上显示“yes”,因为 1 小于或等于 2) test 1 -lt 2 && echo "yes" || echo "no" (在屏幕上显示“yes”,因为 1 小于或等于 2) test 1 -ne ...
abc@abc ~ $ test -e /usr abc@abc ~ $ echo $?0 abc@abc ~ $ test -e /user abc@abc ~ $ echo $?1 下面的命令,测试变量ss是否为空 abc@abc ~ $ ss=22 abc@abc ~ $ test -z $ss abc@abc ~ $ echo $?1 abc@abc ~ $ test -n $ss abc@abc ~ $ echo $?0 ...
test 选项及参数: -e #该文件名是否存在 -f #该文件名是否存在且为文件 -d #该文件名是否存在且为目录 -b #该文件名是否存在且为一个block device设备 -c #该文件名是否存在且为一个character device设备 -S #该文件名是否存在且为一个socket文件 ...
test $INTEGER1 -eq $INTEGER2 2、文件测试: -e file: 测试文件是否存在 -f file: 测试文件是否为普通文件 -d file: 测试指定路径是否为目录 -r file: 测试当前用户对该指定文件是否有读取权限 -w file: 测试当前用户对该指定文件是否有写权限
test用来做条件测试,本次测试用来测试文件是否不存在,如果文件不存在,则返回信息 "the filename $filename do not exist"测试
1. 关于某个文件名的『类型』侦测(存在与否),如 test -e filename -e 该『文件名』是否存在?(常用) -f 该『文件名』是否为文件(file)?(常用) -d 该『文件名』是否为目录(directory)?(常用) -b 该『文件名』是否为一个 block device 装置?
test 1 -le 2 && echo "yes" || echo "no" (在屏幕上显示“yes”,因为 1 小于或等于 2) test 1 -lt 2 && echo "yes" || echo "no" (在屏幕上显示“yes”,因为 1 小于或等于 2) test 1 -ne 2 && echo "yes" || echo "no" ...