0

I can see that the following code is initializing FOO to localhost if BAR is empty, but what's exactly happening with the :-? What is it?

Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
  • 4
    This should help: http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html `${parameter:-word}` _If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted._ – Michael Berkowski Feb 22 '14 at 17:47

1 Answers1

5

If BAR had a non-empty value, FOO would be assigned that value. If not, FOO would be assigned localhost. You can find more ways in Shell Parameter Expansion.

${parameter:-word}

If parameter is unset or null, the expansion of word is substituted.
Otherwise, the value of parameter is substituted.
chepner
  • 497,756
  • 71
  • 530
  • 681
amit_g
  • 30,880
  • 8
  • 61
  • 118