diff options
author | Joas Schilling <coding@schilljs.com> | 2019-04-04 13:42:08 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-04-08 18:00:54 +0300 |
commit | 074d5e306296d63c9163401cbd385b498b23fa8c (patch) | |
tree | 99e1308bc9c75fe6b62e52ff5577385825bbc749 /sample-commands | |
parent | 30cf5c289bf49eb33ac7b2dd8997fdc9d10a5cf4 (diff) |
Add calculator example
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'sample-commands')
-rwxr-xr-x | sample-commands/calc.sh | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sample-commands/calc.sh b/sample-commands/calc.sh new file mode 100755 index 000000000..7ec3c6301 --- /dev/null +++ b/sample-commands/calc.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +while test $# -gt 0; do + case "$1" in + --help) + echo "/calc - A basic calculator for Nextcloud Talk based on gnu BC" + echo "See the official documentation for more information:" + echo "https://www.gnu.org/software/bc/manual/html_mono/bc.html" + echo " " + echo "Simple equations: /calc 3 + 4 * 5" + echo "Complex equations: /calc sin(3) + 3^3 * sqrt(5)" + exit 0 + ;; + *) + break + ;; + esac +done + +CALCULATOR=$(which "bc") +if ! [ -x "$CALCULATOR" ]; then + echo "Basic calculator package (bc) not found" + exit 1 +fi + + +set -f +echo "$@ =" +echo $(echo "$@" | bc) |