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

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

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

 ${Server?}
4条回答
  •  臣服心动
    2020-12-08 06:49

    It means that the script should abort if the variable isn't defined

    Example:

    #!/bin/bash
    echo We will see this
    ${Server?Oh no! server is undefined!}
    echo Should not get here
    

    This script will print out the first echo, and the "Oh no! ..." error message.

    See all the variable substitutions for bash here: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

提交回复
热议问题