代码之家  ›  专栏  ›  技术社区  ›  Kier Calimoso

在Shell脚本中,您称“-a”或hypen/dash(-)之后的任何字母为什么?

  •  1
  • Kier Calimoso  · 技术社区  · 1 年前

    以下是我正在努力理解的项目中的代码。有人能解释它叫什么?(-s和-a)

    if [***-s*** $A ***-a -s*** $B] 
    
    then ..
    
    else ..
    
    fi
    

    还有,有没有一本字典列出了所有的-及其用法?

    谷歌搜索与我需要的信息不完全匹配。因为我不知道叫什么。请帮忙!

    提前谢谢!

    1 回复  |  直到 1 年前
        1
  •  1
  •   Ortomala Lokni    1 年前

    您正在查找条件表达式。假设您使用的是bash,您可以查看以下部分 6.4 Bash Conditional Expressions Bash参考手册。

    -a file
    True if file exists.
    
    -b file
    True if file exists and is a block special file.
    
    -c file
    True if file exists and is a character special file.
    
    -d file
    True if file exists and is a directory.
    
    -e file
    True if file exists.
    
    -f file
    True if file exists and is a regular file.
    
    -g file
    True if file exists and its set-group-id bit is set.
    
    -h file
    True if file exists and is a symbolic link.
    
    -k file
    True if file exists and its "sticky" bit is set.
    
    [...]
    
    

    完整列表请参阅上述文件。