-
-
Notifications
You must be signed in to change notification settings - Fork 2
Linux expr Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to expr on Linux, covering Arch Linux, CachyOS, and other distributions including arithmetic operations, string operations, and expression evaluation.
Basic usage:
# Addition
expr 5 + 3
# Output: 8Important:
# Spaces required around operators
expr 5 + 3 # Correct
expr 5+3 # Wrong (no spaces)
# Must have spaces around +, -, *, etc.Operations:
# Addition
expr 10 + 5
# Subtraction
expr 10 - 5
# Multiplication (escape *)
expr 10 \* 5
# Division
expr 10 / 5
# Modulo
expr 10 % 3Length:
# String length
expr length "Hello World"
# Output: 11Extract substring:
# Substring
expr substr "Hello World" 1 5
# substr string start length
# Output: HelloPattern match:
# Match pattern
expr "Hello" : ".*"
# : = match operator
# Returns length if matchGet match:
# Extract matched part
expr "Hello World" : "\(.*\) World"
# \( \) = capture group
# Output: HelloCheck installation:
# expr is part of coreutils
# Usually pre-installed
# Check expr
which exprThis guide covered expr usage, arithmetic, string operations, and expression evaluation for Arch Linux, CachyOS, and other distributions.
- Bash Scripting Guide - Scripting basics
- bc Guide - Calculator
- awk Guide - Advanced text processing
-
expr Documentation:
man expr
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.