diff --git a/Playground/gh03t/README.txt b/Playground/gh03t/README.txt new file mode 100644 index 0000000..538749d --- /dev/null +++ b/Playground/gh03t/README.txt @@ -0,0 +1,29 @@ +--- GH03T's Simple Calc --- + +/- What is GH03T's Simple Calc + +GH03T's Simple Calc is a minimal, barebones calculator +written entirely in Bash, which wraps `bc` in a user-friendly +CLI interface. + +/- How to Use The Calculator + +To use GH03T's Simple Calc, simply navigate to the `src` +directory, and run the following Bash command, replacing +with your expression of choice - + + ./calc.sh "" + +Note: The expression must be enclosed in quotation marks +to prevent bash from interpreting special characters. + +/- Features Included + +GH03T's Simple Calc supports all of the same features +that `bc` supports, however some are more refined. + +For example, this calculator supports... + +1. The automatic removal of trailing zeros, +2. PEMDAS / order of operations, and +3. A (virtually) infinite expression length. \ No newline at end of file diff --git a/Playground/gh03t/src/calc.sh b/Playground/gh03t/src/calc.sh new file mode 100755 index 0000000..38abda5 --- /dev/null +++ b/Playground/gh03t/src/calc.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Parse Input and Args +expression="$*" + +# Calculate Expression +result=$(echo "$expression" | bc -l) +result=$(awk '{printf "%g\n", $0}' <<< "$result") # remove trailing zeros (0) + +# Return Result +echo "$result" \ No newline at end of file