`
sunxboy
  • 浏览: 2828764 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Operator usage in bash shell

 
阅读更多
Common Bash comparisons
Operator Meaning Example
-z Zero-length string [ -z "$myvar" ]
-n Non-zero-length string [ -n "$myvar" ]
= String equality [ "abc" = "$myvar" ]
!= String inequality [ "abc" != "$myvar" ]
-eq Numeric equality [ 3 -eq "$myinteger" ]
-ne Numeric inequality [ 3 -ne "$myinteger" ]
-lt Numeric strict less than [ 3 -lt "$myinteger" ]
-le Numeric less than or equals [ 3 -le "$myinteger" ]
-gt Numeric strict greater than [ 3 -gt "$myinteger" ]
-ge Numeric greater than or equals [ 3 -ge "$myinteger" ]
-f Exists and is regular file [ -f "$myfile" ]
-d Exists and is directory [ -d "$mydir" ]
-nt First file is newer than second one [ "$myfile" -nt ~/.bashrc ]
-ot First file is older than second one [ "$myfile" -ot ~/.bashrc ]
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics