Created
March 5, 2018 04:41
-
-
Save runnerdave/459f3c251a225b862fb506be6846a38d to your computer and use it in GitHub Desktop.
bash script to test inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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