1

This may sound like a very simple question, but what does

ADB=${ADB:-adb}

do?

I've run it and it sets $ADB to adb , I know the assignment of the value to the ADB shell variable part, but what does ${ADB:-adb} do? I haven't seen this syntax/usage before.

ffledgling
  • 11,502
  • 8
  • 47
  • 69
  • 2
    It was recently commented in http://stackoverflow.com/questions/15143863/bash-colon-operator – fedorqui Mar 01 '13 at 21:11
  • 1
    if the variable `ADB` is not set, then it gets set to `adb`, otherwise it keeps it's old value. This is explained in various FAQs and in the bash manual page – Anya Shenanigans Mar 01 '13 at 21:11

1 Answers1

4

If ADB variable is not set, bash will displays the string adb.

Another trick is to type :

echo ${ADB:=adb}

In this case, ADB variable is assigned with the string adb (still if ADB is not set)

All of these nice features are bash parameter expansions

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223