dots


dots / config / .local / bin
xxwhirlpool  ·  2026-03-21

pcalc

 1#!/usr/bin/env bash
 2
 3if [[ $# -eq 0 ]]; then
 4	echo "Usage: pcalc [PROBLEM]"
 5	exit 1
 6fi
 7
 8# printf cmd will escape spaces & add quotes
 9# so 1+2 and 1 + 2 will have the same result
10# (i think)
11problem=$(printf "%q" "$@")
12
13# if $problem contains spaces, trim it down
14[[ "$problem" =~ [[:space:]] ]]; problem2="${problem//[[:space:]]/}"
15
16# if $problem contains an "x", change to "*"
17# sometimes i type "x" for multiplication
18# perl by default does something else with "x"
19[[ "$problem" =~ x ]]; problem2="${problem2//x/*}"
20
21# fixes some weird thing where a backslash
22# would fuck with the math
23[[ "$problem" =~ \/ ]]; problem2="${problem2//\\}"
24
25# -l adds a newline
26# -e executes $problem
27perl -le "print $problem2"