What is the meaning of a question mark in bash variable parameter expansion as in ${var?}?

后端 未结 4 1885
花落未央
花落未央 2020-12-08 06:46

What is the meaning of a bash variable used like this:

 ${Server?}
4条回答
  •  生来不讨喜
    2020-12-08 07:11

    :? causes the (non-interactive) shell to exit with an error message if given parameter is null or unset. The script you are looking at is omitting the error message; usually, you'd see something like

    foo=${1:?Missing first argument}
    

    For example,

    $ foo=${1:?Missing first argument}
    bash: 1: Missing first argument
    $ set firstarg
    $ foo=${1:?Missing first argument}
    $ echo $foo
    firstarg
    

提交回复
热议问题