Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Playground/gh03t/README.txt
Original file line number Diff line number Diff line change
@@ -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 <expression>
with your expression of choice -

./calc.sh "<expression>"

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.
11 changes: 11 additions & 0 deletions Playground/gh03t/src/calc.sh
Original file line number Diff line number Diff line change
@@ -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"