加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 19:05:11 所属栏目:安全 来源:网络整理
导读:是否有用于bash脚本的所有if开关的列表?有时我看到有人使用它,我想知道他们使用的开关实际上是做什么的。 示例是此中的-z。我知道如何使用它,但我不知道它的来源。 if [ -z "$BASH_VERSION" ]; then echo -e "Error: this script requires the BASH shell
是否有用于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 `['.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读