添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

[ -z "$ENV_VAR" -a -z "$ENV_VAR2" ] has 2 conditions ANDed together using -a switch:

What it means is this:

  • -z "$ENV_VAR" : $ENV_VAR is empty
  • -a : and
  • -z "$ENV_VAR2" : $ENV_VAR2 is empty
  • btw if you're using bash you can refactor this condition to make it bit more succinct:

    [[ -z $ENV_VAR && -z $ENV_VAR2 ]]
                    If you're not using [[ ]], you should use [ ... ] && [ ... ] instead, see Bash Pitfall #6.
    – Benjamin W.
                    Jan 7, 2019 at 17:02
                    That gets you the man page for the external test/[ command, but in Bash, they're built-ins, the help for which is in help test (or man bash).
    – Benjamin W.
                    Jan 7, 2019 at 17:05
    $ [[ -z "" -a -z "" ]] && echo Hello
    bash: syntax error in conditional expression
    bash: syntax error near `-a'
    

    If used with single [ it is the "and" from test. If used with [[ it is the file check from bash.

    The bash solution:

    $ [[ -z "" && -z "" ]] && echo Hello
    Hello
    

    For POSIX compatibility, [[ ... && ... ]] is not available, but -a is considered obsolete (and optional) by POSIX, so use two separate [ commands instead.

    if [ -z "$ENV_VAR" ] && [ -z "$ENV_VAR2" ]; then