【问题标题】:What does the -x and -c string comparison options do?-x 和 -c 字符串比较选项有什么作用?
【发布时间】:2012-07-04 01:32:43
【问题描述】:

当我遇到以下情况时,我正在移植另一个 shell 脚本:

if [[ ! -x $DVDREC ]]; then
  print "ERROR: $DVDREC not found. Exiting ..."
  exit 1
fi

if [[ ! -c ${DVDDEV} ]]; then
  print "ERROR: ${DVDDEV} not found. Exiting ..."
  exit 1
fi

我想知道 -c 和 -x 选项实际上对存储的字符串有什么作用 在 DVDREC 和 DVDDEV 中?

【问题讨论】:

    标签: linux string bash sh hp-ux


    【解决方案1】:

    引用man test

       -c FILE
              FILE exists and is character special
    
       -x FILE
              FILE exists and execute (or search) permission is granted
    

    【讨论】:

    • 感谢您的帮助。我对 Linux 操作系统还很陌生,所以我不知道有用于测试的联机帮助页。
    • @Justin:没问题。对于不熟悉 bash 的人来说,[test 之间的关系并不明显。所以这是一个很好的问题。
    • @justin - 手册页不适用于您将使用的测试命令。 test 内置或 [ 将首先使用。在您的情况下,您使用的是 bash 关键字 [[,而不是命令。标志是一样的。
    【解决方案2】:

    //人工测试

       -c FILE
              FILE exists and is character special
    
       -x FILE
              FILE exists and execute (or search) permission is granted
    

    【讨论】:

      【解决方案3】:

      来自 bash shell 中的“帮助测试”:

        -c FILE        True if file is character special.
        -x FILE        True if the file is executable by you.
      

      【讨论】:

        猜你喜欢
        • 2013-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-21
        相关资源
        最近更新 更多