| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | brt_calc() { |
| 4 | local expr="${*:-}" |
| 5 | if [[ -z "$expr" ]]; then |
| 6 | brt_error 'Usage: brt -calc <expression> (e.g. brt -calc "2 + 2 * 3")' |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
| 10 | if ! command -v bc &>/dev/null; then |
| 11 | brt_error "bc is required for -calc" |
| 12 | exit 1 |
| 13 | fi |
| 14 | |
| 15 | echo "$expr" | bc -l |
| 16 | } |
| 17 | |