I've seen : "${DB_HOST:=localhost}" because it assigns the variable if not set (: $… is just to run assignments standalone).

But that has the same effect like DB_HOST="${DB_HOST:-localhost} (use the string if not set), which is more readable.

While something like echo "${DB_HOST:=localhost}" smells from a mile, because it has output with side-effects.

you are viewing a single comment's thread
view the rest of the comments
[–] [S] 1 point 1 week ago (1 child)

I think it makes it easier to read, because the other variable assignments are also this way. DRY is from a time where one-letter variables were common.

  • source
  • parent
  • hideshow 1 child comment