Default parameters in bash

Often you want to use default values in a bash script. Mostly when you want to make use of optional arguments. You can easily achieve that with parameter substitution.

unset VAR
echo $VAR        # VAR is "default"

VAR=${VAR-another default}
echo $VAR        # VAR is still "default"

There are more parameter substitutions which you can checkout at

Leave a comment

Your email address will not be published. Required fields are marked *