Interview Prep/Shell Scripting/Arrays, conditionals and loops

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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arrays, conditionals and loops