0

I've inherited some bash scripts and I see this one liner

ENV_NAME=${1:-develop}

Can someone tell me what it's doing? I don't even know how to google this.

Thanks!

StephenKing
  • 36,187
  • 11
  • 83
  • 112
Victor
  • 173
  • 1
  • 10
  • Open `man bash` and search on `:-`. (In other words, run `man bash` and type `/:-`) – John1024 Jul 20 '16 at 20:48
  • If you google `site:stackoverflow.com bash colon dash`, you find **several** instances of this question. – Charles Duffy Jul 20 '16 at 20:51
  • http://wiki.bash-hackers.org/syntax/pe is also a great resource – Charles Duffy Jul 20 '16 at 20:51
  • http://mywiki.wooledge.org/BashSheet as well -- if you search for `:-` in that page, you've got a definition. – Charles Duffy Jul 20 '16 at 20:51
  • @CharlesDuffy Dup-voting it was definitely the way to go here. Good point. – hek2mgl Jul 20 '16 at 20:52
  • Here is the page link on the best `bash` manual I saw: [Parameter Substitution](http://tldp.org/LDP/abs/html/parameter-substitution.html) – frist Jul 20 '16 at 20:52
  • @frist, the ABS is an abominably poor resource -- it makes a habit of using bad practices in its examples, so people who learned from it often need to have such practices they picked up by example trained out of them. Please do not encourage its use. – Charles Duffy Jul 20 '16 at 20:55

1 Answers1

0

The construct is a so called parameter expansion. It expands to a default value if the variable itself is not set or null. The semantic is

${variable:-default value}

$1 is the first parameter passed to the script. If the parameter will be omitted ENV_NAME defaults to "develop".

hek2mgl
  • 152,036
  • 28
  • 249
  • 266