Showing posts with label Some bash shell script examples for beginners. Show all posts
Showing posts with label Some bash shell script examples for beginners. Show all posts

Monday, November 14, 2022

Some bash shell script examples for beginners

 even odd


echo "Please enter a number"
read num
if [ `expr $num % 2`  == 0 ]
then
echo "$num is even"
else
echo "$num is odd"
fi


largest of three numbers

echo "please enter 3 numbers"
read num1
read num2
read num3

if test $num1 -gt $num2 -a $num1 -gt $num3
then
echo "$num1 is the greatest"
elif test $num2 -gt $num3
then
echo "$num2 is the greatest"
else
echo "$num3 is the greatest"
fi


calculate net salary


echo "enter basic salary"
read bs
hra=`echo $bs*10/100 | bc`
ta=`echo $bs*15/100 | bc`
da=`echo $bs*2/100 | bc`
pf=`echo $bs*10/100 | bc`
tax=`echo $bs*5/100 | bc`

netsal=`echo $bs+$hra+$ta+$da-$pf-$tax | bc`
echo "net salary is $netsal"


calculate conditional discount and tax


echo  "please enter the amount that you want to buy"
read amount
if test  $amount -lt 1000
then
tax=`echo $amount \* 2/100 | bc`
discount=`echo $amount \* 10/100 | bc`
else
tax=`echo $amount \* 5/100 | bc`
discount=`echo $amount \* 20/100 | bc`
fi

totalcost=`echo $amount - $tax + $discount | bc`
echo  "total cost is $totalcost"