removed blankspace from dir names
This commit is contained in:
76
Task_1/calculator.sh
Executable file
76
Task_1/calculator.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$1" == "--help" ]]
|
||||
then
|
||||
echo "Following options are aviable:
|
||||
add
|
||||
add <int1> <int2>
|
||||
sub
|
||||
sub <int1> <int2>
|
||||
mult
|
||||
mult <int1> <int2>
|
||||
div
|
||||
div <int1> <int2>
|
||||
cross
|
||||
cross <int>
|
||||
"
|
||||
elif [[ "$1" == "cross" ]]
|
||||
then
|
||||
sum=0
|
||||
if [[ $2 ]]
|
||||
then
|
||||
# grep only digits
|
||||
for digit in $(echo "$2" | grep -o [0-9])
|
||||
do
|
||||
sum=$((sum + digit))
|
||||
done
|
||||
echo "Crosssum of $2 = $sum"
|
||||
else
|
||||
read -p "Enter an integer: " n1
|
||||
for digit in $(echo "$n1" | grep -o [0-9])
|
||||
do
|
||||
sum=$((sum + digit))
|
||||
done
|
||||
echo "Crosssum of $n1 = $sum"
|
||||
fi
|
||||
elif [[ "$1" == "add" ]]
|
||||
then
|
||||
if [[ $2 && $3 ]]
|
||||
then
|
||||
echo "$2 + $3 = $(($2+$3))"
|
||||
else
|
||||
read -p "Enter 1st integer: " n1
|
||||
read -p "Enter 2nd integer: " n2
|
||||
echo "$n1 + $n2 = $(($n1+$n2))"
|
||||
fi
|
||||
elif [[ "$1" == "sub" ]]
|
||||
then
|
||||
if [[ $2 && $3 ]]
|
||||
then
|
||||
echo "$2 - $3 = $(($2-$3))"
|
||||
else
|
||||
read -p "Enter 1st integer: " n1
|
||||
read -p "Enter 2nd integer: " n2
|
||||
echo "$n1 - $n2 = $(($n1-$n2))"
|
||||
fi
|
||||
elif [[ "$1" == "mult" ]]
|
||||
then
|
||||
if [[ $2 && $3 ]]
|
||||
then
|
||||
echo "$2 * $3 = $(($2*$3))"
|
||||
else
|
||||
read -p "Enter 1st integer: " n1
|
||||
read -p "Enter 2nd integer: " n2
|
||||
echo "$n1 * $n2 = $(($n1*$n2))"
|
||||
fi
|
||||
elif [[ "$1" == "div" ]]
|
||||
then
|
||||
if [[ $2 && $3 ]]
|
||||
then
|
||||
echo "$2 / $3 = $(($2/$3))"
|
||||
else
|
||||
read -p "Enter 1st integer: " n1
|
||||
read -p "Enter 2nd integer: " n2
|
||||
echo "$n1 / $n2 = $(($n1/$n2))"
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user