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?
Asked
Active
Viewed 225 times
0

Dane O'Connor
- 75,180
- 37
- 119
- 173
-
4This 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 Answers
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.