gpt4 book ai didi

bash - 任何地方都有 'if' 开关列表吗?

转载 作者:行者123 更新时间:2023-11-29 08:42:32 25 4
gpt4 key购买 nike

是否有用于 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 - 任何地方都有 'if' 开关列表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19074542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com