What are : at the beginning of lines used for in a Bash script?
I have seen some usage of : at the beginning of lines, like in the following snippet of code:
cgcreate -g "$cgroups:/$uuid"
: "${BOCKER_CPU_SHARE:=512}" && cgset -r cpu.shares="$BOCKER_CPU_SHARE" "$uuid"
: "${BOCKER_MEM_LIMIT:=512}" && cgset -r memory.limit_in_bytes="$((BOCKER_MEM_LIMIT * 1000000))" "$uuid"
Experiments show that : functions much like a comment (#), since nothing is printed to stdout; however, : $(echo foo > bar) creates a
new file bar, so code execution does happen.