Skip to content

Linux true false Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Linux true and false Guide

Complete beginner-friendly guide to true and false on Linux, covering Arch Linux, CachyOS, and other distributions including boolean commands, exit codes, and script logic.


Table of Contents

  1. true and false Basics
  2. Exit Codes
  3. Script Usage
  4. Conditional Logic
  5. Troubleshooting

true and false Basics

true Command

Basic usage:

# true always succeeds
true

# Exit code: 0 (success)

false Command

Basic usage:

# false always fails
false

# Exit code: 1 (failure)

Exit Codes

Check Exit Code

Verify exit code:

# Check exit code
true
echo $?

# Output: 0 (success)

false
echo $?

# Output: 1 (failure)

Use in Conditions

Conditional logic:

# In if statement
if true; then
    echo "This runs"
fi

if false; then
    echo "This doesn't run"
fi

Script Usage

Infinite Loop

Endless loop:

#!/bin/bash
while true; do
    echo "Running..."
    sleep 1
done

Placeholder

Placeholder command:

#!/bin/bash
# Placeholder for future code
if condition; then
    true  # Do nothing for now
else
    echo "Error"
    false  # Indicate failure
fi

Conditional Logic

Test Conditions

Boolean testing:

#!/bin/bash
if some_command; then
    true  # Success path
else
    false  # Failure path
fi

Short-circuit

Logical operations:

# Short-circuit AND
command1 && true

# Short-circuit OR
command1 || false

Troubleshooting

Commands Not Found

Check installation:

# true and false are part of coreutils
# Usually pre-installed

# Check commands
which true
which false

Summary

This guide covered true and false usage, exit codes, and script logic for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally