• 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          
  • 相关阅读:
    跳转网页
    在代码插入图像的位置
    图像宽度和高度
    添加图像
    指向同一网站中其中的页面的链接
    指向其他网站的链接
    嵌套列表
    定义
    LeetCode561 数组拆分 I
    LeetCode344 反转字符串
  • 原文地址:https://www.cnblogs.com/fangwu/p/8422910.html
Copyright © 2020-2023  润新知