Unix Shell Program
Unix Shell Program
Output
Write a shell program to find a number is Palindrome or not
echo “enter the no to check palendrome”
read n
x=0
y=0
m=$n
while [ $n -ne 0 ] do
x=$(( n % 10 ))
y=$(( y * 10 + x ))
n=$(( n / 10 ))
done
echo “y is $y”
echo “number is $m”
if [ $m -eq $y ]
then
echo “value is palendrome”
else
echo “value is not palendrome”
fi
Output
Write a shell program to find a string is palindrome or not
Output
Write a shell program to find the factorial of a number
factorial
n=0
on=0
fact=1
on=$n
while [ $n -ge 1 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
Output
Write a shell program to find a number is Prime or not
Output
Write a shell program to find Fibonacci series
Output
Write a shell program to find a number is Armstrong or not
Output
Write a shell program to find a year is leap or not
if [ $choice -eq 1 ]
then
echo -n "Enter temperature (C) : "
read tc
# formula Tf=(9/5)*Tc+32
tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
echo "$tf = $tc"
else
Output
Write a shell program to add two numbers
Output
Write a shell program to print a pyramid
#!/bin/bash
Echo “Enter the number”
read count
for((i=1;i<=count;i++))
do
for((j=1;j<=i;j++))
do
echo-n “*”
done
echo
done
exit 0
Output
Write a shell program to find Armstrong number between a
range
#!/bin/bash
i=1
echo “Enter the upper limit”
read n
while((i<=n))
do
c=$i
d=$i
b=0
a=0
while((c>0))
do
a=$((c%10))
b=$((b + a*a*a))
c=$((c/10))
done
if((b==d)); then
echo "$i"
fi
i=$((i+1))
done
output
Write a shell program to print a numeric pyramid
#!/bin/bash number=1
echo "Enter the number" read rows
for((i=1; i<=rows; i++)) do
for((j=1; j<=i; j++))
do
echo -n "$number " number=$((number +
1)) done
number=1 echo
done
Output