------------------------------------------------------------------------
Script 1: Shell script to find the GCD and LCM of two numbers.
------------------------------------------------------------------------
clear
echo Enter two number:
read m n
temp=`expr $m \* $n`
while [ $m != $n ]
do
if [ $m -gt $n ]
then
m=`expr $m - $n`
else
n=`expr $n - $m`
fi
done
echo gcd=$n
lcm=`expr $temp / $n`
echo The LCM is: $lcm
echo The GCD is: $n
output:
$bash gcd_lcm.sh
Enter two number:
2 10
gcd=2
The LCM is: 10
The GCD is: 2
---------------------------------------------------------------------------
Script 2: Shell script to calculate the area of a triangle.
---------------------------------------------------------------------------
clear
echo Enter a base value:
read base
echo Enter the height:
read ht
area=`echo "scale=2; 0.5 * $base * $ht"|bc`
echo the area of the triangle is:$area
output: bash area.sh
Enter a base value:
10
Enter the height:
15
the area of the triangle is:75.0
------------------------------------------------------------------
Script 3: Shell script to find the length of the string
-------------------------------------------------------------------
clear
echo Enter a string:
read str
l=`expr length $str`
echo Length of $str is $l
Enter a String:
youtube
Length of youtube is 7
---------------------------------------------------------------------
Script 4: Shell script to find the factorial of a number.
---------------------------------------------------------------------
clear
echo "Enter an integer:"
read n
fact=1; i=1
while [ $i -le $n ]
do
fact=`expr $fact \* $i`
i=`expr $i + 1`
done
echo Factorial of $n is $fact
Output:
Enter an integer:
5
Factorial of 5 is 120
--------------------------------------------------------------------------
Script 5: #shell script to find if the number is even or odd?
--------------------------------------------------------------------------
clear
echo Enter a number:
read num
if [ `expr $num % 2` -eq 0 ]; then
echo $num is an even
else
echo $num is an odd number.
fi
Output:
Enter a number:
543
543 is an odd number.
2nd Output:
Enter a number:
4574
4574 is an even
-------------------------------------------------------------------------------
for more click the link
Script 1: Shell script to find the GCD and LCM of two numbers.
------------------------------------------------------------------------
clear
echo Enter two number:
read m n
temp=`expr $m \* $n`
while [ $m != $n ]
do
if [ $m -gt $n ]
then
m=`expr $m - $n`
else
n=`expr $n - $m`
fi
done
echo gcd=$n
lcm=`expr $temp / $n`
echo The LCM is: $lcm
echo The GCD is: $n
output:
$bash gcd_lcm.sh
Enter two number:
2 10
gcd=2
The LCM is: 10
The GCD is: 2
---------------------------------------------------------------------------
Script 2: Shell script to calculate the area of a triangle.
---------------------------------------------------------------------------
clear
echo Enter a base value:
read base
echo Enter the height:
read ht
area=`echo "scale=2; 0.5 * $base * $ht"|bc`
echo the area of the triangle is:$area
output: bash area.sh
Enter a base value:
10
Enter the height:
15
the area of the triangle is:75.0
------------------------------------------------------------------
Script 3: Shell script to find the length of the string
-------------------------------------------------------------------
clear
echo Enter a string:
read str
l=`expr length $str`
echo Length of $str is $l
Enter a String:
youtube
Length of youtube is 7
---------------------------------------------------------------------
Script 4: Shell script to find the factorial of a number.
---------------------------------------------------------------------
clear
echo "Enter an integer:"
read n
fact=1; i=1
while [ $i -le $n ]
do
fact=`expr $fact \* $i`
i=`expr $i + 1`
done
echo Factorial of $n is $fact
Output:
Enter an integer:
5
Factorial of 5 is 120
--------------------------------------------------------------------------
Script 5: #shell script to find if the number is even or odd?
--------------------------------------------------------------------------
clear
echo Enter a number:
read num
if [ `expr $num % 2` -eq 0 ]; then
echo $num is an even
else
echo $num is an odd number.
fi
Output:
Enter a number:
543
543 is an odd number.
2nd Output:
Enter a number:
4574
4574 is an even
-------------------------------------------------------------------------------
for more click the link
No comments:
Post a Comment