Finished Övning 4, calculator

This commit is contained in:
Jack-Benny Persson 2013-12-19 16:27:31 +01:00
parent b446f85659
commit 3b94b9a809
5 changed files with 47 additions and 1 deletions

1
Labb6/ovning4/add.sh Symbolic link
View File

@ -0,0 +1 @@
calc.sh

44
Labb6/ovning4/calc.sh Normal file → Executable file
View File

@ -9,26 +9,68 @@
Nr1=$1 Nr1=$1
Nr2=$2 Nr2=$2
# Sanity check
if [ $# -ne 2 ]; then
echo "`basename $0` requires two arguments"
exit 2
fi
if ! [ $Nr1 -eq $Nr2 &> /dev/null ]; then
echo "`basename $0` only takes integers"
exit 2
fi
# Define our functions # Define our functions
add() add()
{ {
Sum=$((Nr1+Nr2)) Sum=$((Nr1+Nr2))
return $Sum
} }
sub() sub()
{ {
Sum=$((Nr1-Nr2)) Sum=$((Nr1-Nr2))
return $Sum
} }
div() div()
{ {
Sum=$((Nr1/Nr2)) Sum=$((Nr1/Nr2))
return $Sum
} }
tim() tim()
{ {
Sum=$((Nr*Nr2)) Sum=$((Nr1*Nr2))
return $Sum
} }
# Main # Main
Calc=`basename $0`
echo $Calc
case "$Calc" in
"add.sh")
add
echo $?
;;
"sub.sh")
sub
echo $?
;;
"div.sh")
div
echo $?
;;
"tim.sh")
tim
echo $?
;;
*)
echo "Please use on the symlink add.sh/sub.sh/div.sh/tim.sh"
exit 2
;;
esac
exit 0

1
Labb6/ovning4/div.sh Symbolic link
View File

@ -0,0 +1 @@
calc.sh

1
Labb6/ovning4/sub.sh Symbolic link
View File

@ -0,0 +1 @@
calc.sh

1
Labb6/ovning4/tim.sh Symbolic link
View File

@ -0,0 +1 @@
calc.sh