“if”列表在哪里切换? [英] List of 'if' switches anywhere?
本文介绍了“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
在这一个。我知道如何使用它,但我不知道它是从哪里派生的。
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 manpage (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 ...
帮助中也解释了这一点: / p>
It is also explained in the help:
$ help [ [: [ arg... ]
This is a synonym for the "test" builtin, but the last
argument must be a literal `]', to match the opening `['.
这篇关于“if”列表在哪里切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文