曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 6017|回复: 1
打印 上一主题 下一主题

[概念] 比较条件列表

[复制链接]

4917

主题

5879

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34382
跳转到指定楼层
楼主
发表于 2009-1-15 11:51:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
String Comparison           Result
                     
string1 = string2        True if the strings are equal
                       (字符串相等则为真)

string1 != string2       True if the strings are not equal
                       (字符串不等则为真)
                     
-n string               True if the string is not null
                       (如果字符串不为空则为真)
                     
-z string               True if the string is null (an empty string)
                        (字符串为空则为真)

Arithmetic Comparison              Result
                           
expression1 -eq expression2     True if the expressions are equal
                                    (两表达式相等则为真)
                           
expression1 -ne expression2     True if the expressions are not equal
                                    (两表达式不等则为真)

expression1 -gt expression2     True if expression1 is greater than expression2
                                  (表达式1 > 表达式2 则为真)
                
expression1 -ge expression2     True if expression1 is greater than or equal to expression2
                                  (表达式1 >= 表达式2 则为真)
                           
expression1 -lt expression2      True if expression1 is less than expression2
                                   (表达式1 < 表达式2 则为真)
                        
expression1 -le expression2      True if expression1 is less than or equal to expression2
                                   (表达式1 <= 表达式2 则为真)
            
! expression                    True if the expression is false, and vice versa


File Conditional                   Result
       
-d file       True if the file is a directory
             (若文件为一目录则为真)

-e file       True if the file exists. Note that historically the -e option has not been portable, so -f is usually used.
             (文件存在则为真.注意,-e 选项显得不太轻便,故 -f 则比较常用)

-f file       True if the file is a regular file
             (文件是个普通文件则为真

-g file       True if set-group-id is set on file
              (如果文件的 sgid 设置了就为真)

-r file        True if the file is readable
              (如果文件可读则为真)

-s file        True if the file has nonzero size
              (文件非 0 字节时为真)

-u file        True if set-user-id is set on file
              (如果文件设置了 suid 则为真)

-w file        True if the file is writable
              (如果文件可写则为真)

-x file        True if the file is executable
              (如果文件可执行则为真)







      

4917

主题

5879

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34382
沙发
 楼主| 发表于 2009-1-16 20:03:05 | 只看该作者

示例代码一

#!/bin/sh

if [ -f /bin/bash ]
then
echo "file /bin/bash exists"
fi

if [ -d /bin/bash ]
then
echo "/bin/bash is a directory"
else
echo "/bin/bash is NOT a directory"
fi
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2024-5-14 20:39 , Processed in 0.081749 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表