Terminal calculator for floating-point expressions with interactive REPL
A Bash wrapper around bc that fixes its poor terminal UX by providing readline history, proper Ctrl-C handling, and a clean REPL interface.
GitHub: Open-Technology-Foundation/bcx
- Interactive REPL with readline history (arrow keys, Ctrl-R search)
- Single-expression mode for quick calculations
- Persistent command history (
~/.bcx_history) - x → * conversion in terminal mode (e.g.,
3x4becomes3*4) - Clean error handling with clear feedback
- Math library support (sqrt, sin, cos, etc.)
# Copy to system path
sudo cp bcx /usr/local/bin/
sudo chmod +x /usr/local/bin/bcx
# Optional: Install bash completion
sudo cp .bash_completion /etc/bash_completion.d/bcx
# Optional: Create alias for quick access
echo "alias ?='bcx'" >> ~/.bashrcSingle-expression evaluation:
bcx "3.14 * 2" # 6.28
bcx "sqrt(144)" # 12
bcx 42x72/3.14 # x converts to * in terminal modeInteractive REPL:
$ bcx
> 2 + 2
4
> sqrt(16)
4
> ^DAs command alias:
? 23x42 # Quick calculation
? "scale=4; 22/7" # Pi approximationIn scripts (non-terminal mode):
result=$(bcx "42 * 72 / 3.14")
echo "Result: $result"- Bash 4.0+
bccommand-line calculator- Linux/Unix terminal with readline support
This script follows the Bash Coding Standard with proper error handling, readonly constants, and structured organization.
Contributions are welcome! Please feel free to submit a Pull Request.
GNU General Public License v3.0 - see LICENSE.
Gary Dean | garydean.id