一、使用 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          

 

相关文章:

  • 2021-09-29
  • 2021-11-23
  • 2021-04-01
  • 2021-06-15
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
猜你喜欢
  • 2021-12-19
  • 2021-07-13
  • 2021-09-16
  • 2022-12-23
  • 2021-06-25
  • 2022-01-07
  • 2022-02-07
相关资源
相似解决方案