01 / 01

Use It Anyway

A Shell Colon Does Nothing

Based on Hacker News Discussion

135 points

02

The Magic of the Colon

A command that does nothing, yet does everything

What is the Colon Command?

  • 01
    A Built-in Shell Command The colon (:) is a shell built-in that returns true (exit code 0)
  • 02
    Does Absolutely Nothing It executes no operation, no side effects, nothing happens
  • 03
    Also Known As 'True' Functionally equivalent to the 'true' command in most shells
  • 04
    Exists in Every Shell Available in Bash, Zsh, Fish, and all POSIX-compliant shells

The Colon in Action

shell-example.sh
# The colon command - does nothing, returns true
:

# Equivalent to 'true' command
: && echo "Success!"

# Exit status is always 0
: ; echo $?

The colon command executes successfully and returns exit code 0, making it perfect for control flow and placeholder scenarios.

05

Why Use It?

Practical patterns that make the colon indispensable

Real-World Use Cases

sync

Infinite Loops

Create clean while loops: while :; do ...; done

edit_note

Parameter Expansion

Default values syntax: : ${VAR:=default}

comment

Multi-line Comments

Block comments: : 'comment text here'

settings

Placeholder Commands

Stub functions and config file placeholders

code

Conditional Execution

Safe if-then syntax when you need no action

speed

Performance

Built-in command—no external process overhead

0
Operations executed by the colon command
Yet it's one of the most useful commands in shell scripting—elegance in simplicity

Thank You

Sometimes the most powerful tools do the least

Source: refp.se/articles/your-shell-and-the-magic-colon
Made with AirSlide
𝕏 in