zoukankan      html  css  js  c++  java
  • Linux Shell_test

    test: 测试Shell脚本里的条件,通过推出状态返回其结果。
    用法:
        test [ expression ] 或 [ [ expression ] ]
        注意空格
    test表达式:是则为真
        字符串测试:
          string     测试字符串不为空
          -n string  测试字符串非null
          -z string  测试字符串为null
          s1 = s2    两字符串相同
          s1 != s2   两字符串不相同
      
      文件测试:
          -b file    文件是块设备
          -c file    文件是字符设备
          -d file    文件是目录
          -e file    文件是一般文件
          -g file    文件有设置它的setgid位
          -u file    文件有设置它的setuid位
          -h/L file  文件是符号链接
          -p file    文件是管道文件
          -r file    文件可读
          -w file    文件可写
          -x file    文件可执行,或者是可被查找的目录
          -s file    文件是socket
          -s file    文件不是空的
          -t n       文件描述符指向一终端
           
        整数测试:
          n1 -eq n2  整数n1 n2相等
          n1 -ne n2  整数n1 n2不相等
          n1 -lt n2  n1小于n2
          n1 -gt n2  n1大于n2
          n1 -le n2  n1小于等于n2
          n1 -ge n2  n1大于等于n2
       
    在测试多个条件是否成立时可以使用 -a(做逻辑AND)
    在测试在多个条件中是否有某一个成立时可以使用 -o(做逻辑或)
    -a -o是test运算符,它们与&& ||(Shell运算符)之间有一个差异点
    if [ -n "$str" -a -f "$file" ]
    if [ -n "$str" ] && [ -f "$file" ]

  • 相关阅读:
    卷积:如何成为一个很厉害的神经网络
    卷积的本质及物理意义(全面理解卷积)
    傅里叶分析之掐死教程(完整版)
    buf.writeUInt16BE()
    buf.writeUInt8()函数详解
    buf.writeUIntBE()函数详解
    buf.writeInt32BE()函数详解
    buf.writeInt16BE()函数详解
    buf.writeInt8()函数详解
    buf.writeDoubleBE()函数详解
  • 原文地址:https://www.cnblogs.com/lnlin/p/7089775.html
Copyright © 2011-2022 走看看