

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


To write a shell script to find whether a string is palindrome or not and to find length of a string without using inbuilt string. 1.SHELL SCRIPT PROGRAM TO CHECK WHETHER A STRING IS PALINDROME: ALGORITHM: Start the program Let the user input a string Checks each and every word from front and back With the done statement, displays palindrome or not Stop the program PROGRAM CODE: #!/bin/bash echo "Enter a string to be entered:" read str echo len=echo $str | wc -c len=expr $len - 1 i= 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" OUTPUT:
2.CALCULATE STRING LENGTH WITHOUT USING INBUILT FUNCTION: ALGORITHM: Start the program Let the user input a string Counts each and every statement With the done statement, display the length Stop the program SOURCE CODE: !#/bin/bash echo “Enter the string:” read str i= val= len= IFS= ‘’ read –a strarr <<< “$str” echo “There are ${#strarr[*]} words in the text” while [ “$i” –lt “${#str}” ]; do val= “${str:$i:1}” len = $(( len+1 )) i=$(( i+1 )) done echo “The length of the string is: $len” OUTPUT: RESULT: Thus the case study on the operators, looping statements and conditional statements have done, and applied the insights in executing the programs.