Overview - Default values (${var:-default})
What is it?
In bash scripting, default values allow you to use a fallback value when a variable is empty or unset. The syntax ${var:-default} means: if 'var' has a value, use it; otherwise, use 'default'. This helps scripts run smoothly even if some variables are missing or empty. It is a simple way to avoid errors and provide sensible defaults.
Why it matters
Without default values, scripts can fail or behave unpredictably when variables are missing or empty. This can cause crashes or wrong results, especially in automation where inputs may vary. Default values make scripts more reliable and user-friendly by ensuring there is always a valid value to work with. They save time debugging and prevent unexpected failures.
Where it fits
Before learning default values, you should understand basic bash variables and how to use them. After mastering default values, you can learn more advanced parameter expansions and conditional expressions to write robust scripts.