Categories
Development OS tricks

Bash #3 – Default values

When handling parameters from the command line I usually want one or two parameters to have a default value. In Bash I can achieve this through:

DIRECTORY=${DIRECTORY_FROM_COMMAND_LINE:-"/tmp"}

Where “DIRECTORY_FROM_COMMAND_LINE” is just another variable and thus can be 1 (for $1).

Leave a Reply

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