Linux bc Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux bc Guide
Complete beginner-friendly guide to bc on Linux, covering Arch Linux, CachyOS, and other distributions including calculator operations, mathematical calculations, and precision arithmetic.
Table of Contents
bc Installation
Install bc
Arch/CachyOS:
# Install bc
sudo pacman -S bc
Debian/Ubuntu:
sudo apt install bc
Fedora:
sudo dnf install bc
bc Basics
Simple Calculation
Basic usage:
# Calculate
echo "5 + 3" | bc
# Output: 8
Multiple Operations
Chain operations:
# Multiple operations
echo "5 + 3 * 2" | bc
# Output: 11 (follows order of operations)
Interactive Mode
Start Calculator
Interactive:
# Start bc
bc
# Then type calculations:
# 5 + 3
# 10 * 2
# quit
Scale (Decimal Places)
Set precision:
# In bc:
# scale=2
# 10 / 3
# Output: 3.33
Script Mode
From File
Calculate from file:
# Create script
echo "5 + 3" > calc.txt
echo "10 * 2" >> calc.txt
# Run script
bc calc.txt
Inline Calculation
One-liner:
# Inline calculation
bc <<< "5 + 3"
# Output: 8
Troubleshooting
bc Not Found
Check installation:
# Check bc
which bc
# Install if missing
sudo pacman -S bc
Summary
This guide covered bc usage, calculator operations, and mathematical calculations for Arch Linux, CachyOS, and other distributions.
Next Steps
- expr Guide - Expression evaluation
- Bash Scripting Guide - Scripting basics
- bc Documentation:
man bc
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.