0

I see the following line in a shell script.

CATALINA_BASE=${CATALINA_BASE:-${APP_HOME}/tomcat}

Is the :- like an if statement? That is, if the environment variable $CATALINA_BASE exists, use its value for the variable CATALINA_BASE?

I also see this line:

APP_USER=${APP_USER:?}

What does the ? mean? In this case, there is no -.

BJ Dela Cruz
  • 5,194
  • 13
  • 51
  • 84

1 Answers1

3

${foo:-bar} and ${foo:bar} are both parameter expansions with defaults. They vary in terms of how they expand an explicitly-set empty string (as opposed to a null, unset string).

See http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html, http://mywiki.wooledge.org/BashFAQ/073, or http://mywiki.wooledge.org/BashSheet#Parameter_Operations for explanations of these and more.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441