Bash ---- [ and [[ memo

  • Tests supported by [ (also known as test):

    • -e FILE: True if file exists.

    • -f FILE: True if file is a regular file.

    • -d FILE: True if file is a directory.

    • -h FILE: True if file is a symbolic link.

    • -p PIPE: True if pipe exists.

    • -r FILE: True if file is readable by you.

    • -s FILE: True if file exists and is not empty.

    • -t FD : True if FD is opened on a terminal.

    • -w FILE: True if the file is writable by you.

    • -x FILE: True if the file is executable by you.

    • -O FILE: True if the file is effectively owned by you.

    • -G FILE: True if the file is effectively owned by your group.

    • FILE -nt FILE: True if the first file is newer than the second.

    • FILE -ot FILE: True if the first file is older than the second.

    • -z STRING: True if the string is empty (it's length is zero).

    • -n STRING: True if the string is not empty (it's length is not zero).

    • STRING = STRING: True if the first string is identical to the second.

    • STRING != STRING: True if the first string is not identical to the second.

    • STRING < STRING: True if the first string sorts before the second.

    • STRING > STRING: True if the first string sorts after the second.

    • EXPR -a EXPR: True if both expressions are true (logical AND).

    • EXPR -o EXPR: True if either expression is true (logical OR).

    • ! EXPR: Inverts the result of the expression (logical NOT).

    • INT -eq INT: True if both integers are identical.

    • INT -ne INT: True if the integers are not identical.

    • INT -lt INT: True if the first integer is less than the second.

    • INT -gt INT: True if the first integer is greater than the second.

    • INT -le INT: True if the first integer is less than or equal to the second.

    • INT -ge INT: True if the first integer is greater than or equal to the second.

  • Additional tests supported only by [[:

    • STRING = (or ==) PATTERN: Not string comparison like with [ (or test), but pattern matching is performed. True if the string matches the glob pattern.

    • STRING =~ REGEX: True if the string matches the regex pattern.

    • ( EXPR ): Parantheses can be used to change the evaluation precedence.

    • EXPR && EXPR: Much like the '-a' operator of test, but does not evaluate the second expression if the first already turns out to be false.

    • EXPR || EXPR: Much like the '-o' operator of test, but does not evaluate the second expression if the first already turns out to be true.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值