bash中的-s, -z, -e, -f, -d…

Shell Liemer_Lius 2998℃

 

条件表达式用于 [[ 复合命令以及内建命令 test 和 [ 中, 用来测试文件属性,进行字符串和算术比较。表达式使用下面的单目或二进制操作构造。 如果某操作的任何 file 参数的形式是
/dev/fd/n,那么将检查 文件描述符 n。如果某操作的 file 参数是 /dev/stdin, /dev/stdout 或者 /dev/stderr 之一,将分别检查文件描述符 0,1 和 2。
-a file
如果 file 存在则为真。
-b file
如果 file 存在且为块设备则为真。
-c file
如果 file 存在且为字符设备则为真。
-d file
如果 file 存在且是一个目录则为真。
-e file
如果 file 存在则为真。
-f file
如果 file 存在且为普通文件则为真。
-g file
如果 file 存在且是设置组ID的 (sgid) 则为真。
-h file
如果 file 存在且为符号链接则为真。
-k file
如果 file 存在且设置了 ``sticky'' 位 (粘滞位) 则为真。
-p file
如果 file 存在且是一个命名管道 (FIFO) 则为真。
-r file
如果 file 存在且可读则为真。
-s file
如果 file 存在且大小大于零则为真。
-t fd 如果文件描述符 fd 是打开的且对应一个终端则为真。
-u file
如果 file 存在且是设置用户ID的 (suid) 则为真。
-w file
如果 file 存在且可写则为真。
-x file
如果 file 存在且可执行则为真。
-O file
如果 file 存在且为有效用户ID所拥有则为真。
-G file
如果 file 存在且为有效组ID所拥有则为真。
-L file
如果 file 存在且为符号链接则为真。
-S file
如果 file 存在且为套接字则为真。
-N file
如果 file 存在且上次读取后被修改过则为真。
file1 -nt file2
如果 file1 比 file2 要新 (根据修改日期),或者 如果 file1 存在而 file2 不存在,则为真。
file1 -ot file2
如果 file1 比 file2 更旧,或者 如果 file1 不存在而 file2 存在,则为真。
file1 -ef file2
如果 file1 和 file2 指的是相同的设备和 inode 号则为真。
-o optname
如果启用了 shell 选项 optname 则为真。参见下面对内建命令 set 的 -o 选项的描述中的选项列表。
-z string
如果 string 的长度为 0 则为真。
-n string
string 如果 string 的长度非 0 则为真。
string1 == string2
如果字符串相等则为真。= 可以用于使用 == 的场合来兼容 POSIX 规范。
string1 != string2
如果字符串不相等则为真。
string1 < string2
如果 string1 在当前语言环境的字典顺序中排在 string2 之前则为真。
string1 > string2
如果 string1 在当前语言环境的字典顺序中排在 string2 之后则为真。

 

转载请注明:liutianfeng.com » bash中的-s, -z, -e, -f, -d…

喜欢 (3)

评论已关闭。