2019-04-14 18:30:59 +00:00
|
|
|
#!/bin/bash
|
2019-04-29 16:50:36 +00:00
|
|
|
# file: calc.sh
|
2019-05-01 17:21:57 +00:00
|
|
|
# example for an interactive chat, run with startproc calc.sh
|
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
|
|
|
#
|
2020-06-12 09:11:17 +00:00
|
|
|
#### $$VERSION$$ v0.96-0-g3871ca9
|
2020-06-07 11:30:59 +00:00
|
|
|
|
|
|
|
######
|
|
|
|
# parameters
|
|
|
|
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
|
|
|
# $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
|
|
|
|
|
|
|
|
echo 'Starting Calculator ...'
|
|
|
|
echo 'Enter first number.'
|
2020-06-07 11:30:59 +00:00
|
|
|
read -r A <"${INPUT}"
|
2019-04-14 18:30:59 +00:00
|
|
|
echo 'Enter second number.'
|
2020-06-07 11:30:59 +00:00
|
|
|
read -r B <"${INPUT}"
|
2019-04-15 14:44:26 +00:00
|
|
|
echo 'Select Operation: mykeyboardstartshere [ "Addition" , "Subtraction" , "Multiplication" , "Division" , "Cancel" ]'
|
2020-06-07 11:30:59 +00:00
|
|
|
read -r opt <"${INPUT}"
|
2019-04-14 18:30:59 +00:00
|
|
|
echo -n 'Result: '
|
|
|
|
case $opt in
|
2019-04-16 11:29:49 +00:00
|
|
|
'add'* | 'Add'* ) res="$(( A + B ))" ;;
|
|
|
|
'sub'* | 'Sub'* ) res="$(( A - B ))" ;;
|
|
|
|
'mul'* | 'Mul'* ) res="$(( A * B ))" ;;
|
|
|
|
'div'* | 'Div'* ) res="$(( A / B ))" ;;
|
|
|
|
'can'* | 'Can'* ) res="abort!" ;;
|
2019-04-14 18:30:59 +00:00
|
|
|
* ) echo "unknown operator!";;
|
|
|
|
esac
|
2019-04-16 11:29:49 +00:00
|
|
|
echo "$res"
|
2019-04-14 18:30:59 +00:00
|
|
|
echo "Bye .."
|
2020-06-07 11:30:59 +00:00
|
|
|
|