GTU OS Program - 10

10. Write a shell script to check entered string is palindrome or not.

Complete code

echo "Enter the string to check: "
read str
len=`echo $str | wc -c`
len=`expr $len - 1`
i=1
j=`expr $len / 2`
while test $i -le $j
do
        k=`echo $str | cut -c $i`
        l=`echo $str | cut -c $len`
        if test $k != $l
        then
                echo "String is not Palindrome"
                exit
        fi
        i=`expr $i + 1`
        len=`expr $len - 1`
done
echo "String is Palindrome" 

Interpreting the palindrome.sh file and executing it in terminal

tkanu025@hp:~/lab_solutions$ chmod +x palindrome.sh
tkanu025@hp:~/lab_solutions$ ./palindrome.sh
Output

gtu os lab manual,

os GTU Practical,

operating system Programs,

Operating system shellscript programs,

Gtu study material 3140705,

OS 3140702,

os practical list,

shell script programming,

gtu os practical,

os lab solution gtu

Comments

YouTube

Popular posts from this blog

GTU OOP Programs - 11

Mini project ideas for Operating System

GTU OS Program - 8