shell 测试命令

一、使用 test 命令可以对文件、字符串等进行测试,一般配合控制语句使用。

1、字符串测试

test str1 = str2    //测试字符串是否相等
test str1 != str2    //测试字符串是否不相等
test str1    //测试字符串是否部位空
test -n str1    //测试字符串是否部位空
test -z str1    //测试字符串是否为空

2、整数测试

test int1 -eq int2    //测试整数是否相等
test int1 -ne int2    //测试整数是否不相等
test int1 -gt int2    //测试 int1 是否 > int2
test int1 -ge int2    //测试 int1 是否 >= int2
test int1 -lt int2    //测试 int1 是否 < int2
test int1 -le int2    //测试 int1 是否 <= int2

3、文件测试

test -d file    //指定文件是否是目录
test -f file    //指定文件是否是常规文件
test -x file    //指定文件是否可执行
test -r file    //指定文件是否可读
test -w file    //指定文件是否写
test -a file    //指定文件是否存在
test -s file    //文件大小是否不是 0          

 

posted @ 2018-02-06 16:21  方方方方方方  阅读(244)  评论(0编辑  收藏  举报