

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Two shell scripting programs. The first program checks whether a given string is a palindrome or not. The second program finds the length of a string without using built-in functions. Both programs are written in bash.
Typology: Lab Reports
1 / 3
This page cannot be seen from the preview
Don't miss anything!


!#/bin/bash echo –n “Enter the string:”; read str str=${str1,,} len=${#str} palindrome= “true” let mid=len/ let j=len- for (( i=0; i<$mid; i++ )) do left=${str:$i:1} right=${str:$j:1} let j=j- if [ $left != $right ]; then palindrome = “false” fi done if [ $palindrome = “true” ]; then echo “The string $str is a palindrome” else echo “The string $str is a palindrome” fi OUTPUT:
SHELL SCRIPT PROGRAM TO FIND THE LENGTH OF THE STRING WITHOUT INBUILT FUNCTIONS: !#/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: