0

I have seen the following usage of script.

export CONFIG=${X_CONFIG:-${Y_CONFIG}}

Question> what is the real meaning of this script?

Thank you

q0987
  • 34,938
  • 69
  • 242
  • 387
  • Is it really reasonable to have a question asking what syntax X means for every possible syntactical construct in a language? That's the direction this goes down. – Charles Duffy Mar 24 '16 at 21:47
  • ...for relevant references, see http://wiki.bash-hackers.org/syntax/pe, http://mywiki.wooledge.org/BashGuide/Parameters#Parameter_Expansion, http://mywiki.wooledge.org/BashFAQ/073, http://tiswww.case.edu/php/chet/bash/bash.html#lbBB, http://mywiki.wooledge.org/BashSheet#Parameter_Operations, etc. – Charles Duffy Mar 24 '16 at 21:47
  • As an aside -- all-caps variable names are reserved by convention for variables with meaning to the shell or system; see fourth paragraph of the relevant spec at http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html, reserving the namespace of variables with at least one lower-case character for application-defined use. (While only environment variables are explicitly in-scope for that portion of the POSIX spec, shell variables share that namespace, so the convention applies to them as well). – Charles Duffy Mar 25 '16 at 14:45

1 Answers1

2

${X_CONFIG:-${Y_CONFIG}}} is a parameter expansion for a default value.

That is to say: It expands to the value of X_CONFIG if set to a non-null value, or Y_CONFIG if X_CONFIG was either unset or null.

Thus, the effect of the statement as a whole is to assign a variable CONFIG to have an identical value to either $X_CONFIG or $Y_CONFIG, and export that variable to the environment.

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