Member-only story
The One-Character Bash Command You Should Know
Here is one of those questions I have seen being asked in interviews because it looks much more complicated than it actually is.
Suppose I show you these two Bash loops:
# First loop
while :
do
done
# Second loop
while true
do
doneThen I ask a simple question:
Why is : used in the first one while true is used in the second?
This is where things usually get entertaining. People start looking for some deep difference in behavior. They draw diagrams, write formulas, invent hypotheses, and sometimes become convinced that the two loops must produce different results because, well, why would anyone write two different commands if they did exactly the same thing? Except they do the same thing…………………………
: is a Bash Command
The first important detail is that : is not special punctuation in this context.
It is a shell builtin. Run it:
:
echo $?You get:
0The colon command does nothing and returns a successful exit status. That makes it useful anywhere Bash expects a command whose success or failure controls what happens next and while needs exactly that.




