Linux true false Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
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
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
- test Guide - Conditional testing
- Bash Scripting Guide - Scripting basics
- true Documentation:
man true - false Documentation:
man false
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.