How to build a conditional assignment in bash?

If you want a way to define defaults in a shell script, use code like this:

: ${VAR:="default"}

Yes, the line begins with ‘:’. I use this in shell scripts so I can override variables in ENV, or use the default.

This is related because this is my most common use case for that kind of logic. ;]

Leave a Comment