2019-04-14 18:30:59 +00:00
|
|
|
#!/bin/bash
|
2021-01-01 21:48:13 +00:00
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# File: calc.sh
|
|
|
|
#
|
|
|
|
# Description: example for an background job, see mycommands.sh.dist
|
|
|
|
#
|
|
|
|
# Usage: runback calc example/calc.sh - or run in terminal
|
|
|
|
# killback calc - to stop background job
|
2020-06-07 11:30:59 +00:00
|
|
|
#
|
2019-04-14 18:30:59 +00:00
|
|
|
# This file is public domain in the USA and all free countries.
|
|
|
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
2020-06-07 11:30:59 +00:00
|
|
|
#
|
2021-01-03 21:39:36 +00:00
|
|
|
#### $$VERSION$$ v1.21-0-gc85af77
|
2021-01-01 21:48:13 +00:00
|
|
|
########################################################################
|
2020-06-07 11:30:59 +00:00
|
|
|
|
|
|
|
######
|
|
|
|
# parameters
|
2020-06-23 14:35:50 +00:00
|
|
|
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
2020-06-07 11:30:59 +00:00
|
|
|
# $3 path to named pipe/log
|
2019-04-14 18:30:59 +00:00
|
|
|
|
2020-06-07 11:30:59 +00:00
|
|
|
INPUT="${3:-/dev/stdin}"
|
2019-04-14 18:30:59 +00:00
|
|
|
|
|
|
|
# adjust your language setting here
|
|
|
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
|
|
|
export 'LC_ALL=C.UTF-8'
|
|
|
|
export 'LANG=C.UTF-8'
|
|
|
|
export 'LANGUAGE=C.UTF-8'
|
|
|
|
|
|
|
|
unset IFS
|
|
|
|
# set -f # if you are paranoid use set -f to disable globbing
|
|
|
|
|
2021-01-01 21:48:13 +00:00
|
|
|
printf 'Starting Calculator ...\n'
|
|
|
|
printf 'Enter first number.\n'
|
2020-06-07 11:30:59 +00:00
|
|
|
read -r A <"${INPUT}"
|
2021-01-01 21:48:13 +00:00
|
|
|
printf 'Enter second number.\n'
|
2020-06-07 11:30:59 +00:00
|
|
|
read -r B <"${INPUT}"
|
2021-01-01 21:48:13 +00:00
|
|
|
printf 'Select Operation: mykeyboardstartshere [ "Addition" , "Subtraction" , "Multiplication" , "Division" , "Cancel" ]\n'
|
2020-06-07 11:30:59 +00:00
|
|
|
read -r opt <"${INPUT}"
|
2021-01-01 21:48:13 +00:00
|
|
|
printf 'Result: '
|
|
|
|
case ${opt,,} in
|
|
|
|
'a'*) res="$(( A + B ))" ;;
|
|
|
|
's'*) res="$(( A - B ))" ;;
|
|
|
|
'm'*) res="$(( A * B ))" ;;
|
|
|
|
'd'*) res="$(( A / B ))" ;;
|
|
|
|
'c'*) res="abort!" ;;
|
|
|
|
* ) printf "unknown operator!\n";;
|
2019-04-14 18:30:59 +00:00
|
|
|
esac
|
2021-01-01 21:48:13 +00:00
|
|
|
printf "%s\nBye ...\n" "${res}"
|
2020-06-07 11:30:59 +00:00
|
|
|
|