Bash

true, false and : commands

Syntax#

  • true, : - always return 0 as exit code.
  • false - always returns 1 as exit code.

Infinite Loop

while true; do
    echo ok
done

or

while :; do
   echo ok
done

or

until false; do
    echo ok
done

Function Return

function positive() {
    return 0
}

function negative() {
    return 1
}

Code that will always/never be executed

if true; then
    echo Always executed
fi
if false; then
    echo Never executed
fi

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow