是否有任何地方的“if"开关列表? [英] Is there a list of 'if' switches anywhere?

查看:28
本文介绍了是否有任何地方的“if"开关列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有在 Bash 脚本中使用的所有 if 开关的列表?有时我看到有人在使用它,我想知道他们使用的开关实际上是做什么的.

Is there a list of all the if switches for use in Bash scripting? Sometimes I see someone using it and I wonder what the switch they're using actually does.

这个例子中的 -z 就是一个例子.我知道如何使用它,但我不知道它的来源.

An example is the -z in this one. I know how to use it, but I don't know where it was derived from.

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

任何参考、指南、帖子、答案将不胜感激.

Any references, guides, posts, answers would be appreciated.

推荐答案

查看 Bash 手册页 (man bash).选项在 CONDITIONAL EXPRESSIONS 部分指定:

Look at the Bash man page (man bash). The options are specified in the CONDITIONAL EXPRESSIONS section:

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 `['.

这篇关于是否有任何地方的“if"开关列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆