Skip to content

Instantly share code, notes, and snippets.

@runnerdave
Created March 5, 2018 04:41
Show Gist options
  • Save runnerdave/459f3c251a225b862fb506be6846a38d to your computer and use it in GitHub Desktop.
Save runnerdave/459f3c251a225b862fb506be6846a38d to your computer and use it in GitHub Desktop.
bash script to test inputs
#!/bin/bash
# set -f only works when run in the prompt before executing the script, may be due to my
# local setup
set -f
expr "${1}" "${2}" "${3}"
if [ $# -lt 3 ]
then
echo "Usage : $0 Operand Operation Operand"
exit
fi
case "$2" in
+) echo "Addition"
echo $(($1 + $3))
;;
-) echo "Subtraction"
echo $(($1 - $3))
;;
\*) echo "Multiplication"
echo $(($1 * $3))
;;
/) echo "Division"
echo $(($1 / $3))
;;
*) echo "Operation '$2' not valid"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment