bash – 任何地方’if’切换列表?

前端之家收集整理的这篇文章主要介绍了bash – 任何地方’if’切换列表?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有用于bash脚本的所有if开关的列表?有时我看到有人使用它,我想知道他们使用的开关实际上是做什么的。

示例是此中的-z。我知道如何使用它,但我不知道它的来源。

if [ -z "$BASH_VERSION" ]; then
    echo -e "Error: this script requires the BASH shell!"
    exit 1
fi

任何参考,指南,帖子,答案将不胜感激。

看看bash手册页(man bash)。选项在CONDITIONAL EXPRESSIONS部分中指定:
CONDITIONAL EXPRESSIONS
       Conditional expressions are used by the [[  compound  command  and  the
       test  and [ builtin commands to test file attributes and perform string
       and arithmetic comparisons.  Expressions are formed from the  following
       unary  or  binary  primaries.   If any file argument to one of the pri-
       maries is of the form /dev/fd/n,then file descriptor n is checked.  If
       the  file  argument  to  one  of  the  primaries  is one of /dev/stdin,/dev/stdout,or /dev/stderr,file descriptor 0,1,or 2,respectively,is checked.

       Unless otherwise specified,primaries that operate on files follow sym-
       bolic links and operate on the target of the link,rather than the link
       itself.

       -a file
              True if file exists.
       ... more options ...

它也在帮助中解释:

$ help [ [: [ arg... ]
    This is a synonym for the "test" builtin,but the last
    argument must be a literal `]',to match the opening `['.

猜你在找的Bash相关文章