GTU OS Program - 10

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

Complete code

  1. echo "Enter the string to check: "
  2. read str
  3. len=`echo $str | wc -c`
  4. len=`expr $len - 1`
  5. i=1
  6. j=`expr $len / 2`
  7. while test $i -le $j
  8. do
  9. k=`echo $str | cut -c $i`
  10. l=`echo $str | cut -c $len`
  11. if test $k != $l
  12. then
  13. echo "String is not Palindrome"
  14. exit
  15. fi
  16. i=`expr $i + 1`
  17. len=`expr $len - 1`
  18. done
  19. echo "String is Palindrome"

Interpreting the palindrome.sh file and executing it in terminal

  1. tkanu025@hp:~/lab_solutions$ chmod +x palindrome.sh
  2. 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 OS Program - 11 Filters

GTU OS Program - 13 Date Validator

GTU OS Program - 8