What is the `:` (colon) command and where is it useful?
IntermediateConceptArrays, conditionals and loops
Answer
: is a builtin that does nothing and returns 0. Uses:
: "${APP_ENV:=dev}" # apply a default without running anything
: > /var/log/app/debug.log # truncate a file
while :; do check; sleep 60; done # infinite loop
if is_ready; then :; else start; fi # placeholder branch
The arguments are still expanded, which is exactly why : "${VAR:?msg}" works as an assertion.
More on Arrays, conditionals and loops
How do you declare, populate and iterate an indexed array?BeginnerWhat is the difference between `"${arr[@]}"` and `"${arr[*]}"`?IntermediateHow do associative arrays work and what are they good for in DevOps scripts?IntermediateHow do you read a command's output into an array correctly?IntermediateWhat is the difference between `[ ]`, `[[ ]]` and `(( ))`?BeginnerWhy does `[ $var = "prod" ]` fail when `var` is empty or contains spaces?Intermediate