Shell Scripting Programs: Palindrome Checker and Length Finder, Lab Reports of Microcomputers

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

2020/2021

Uploaded on 02/10/2021

nikhil-balasubramanian
nikhil-balasubramanian 🇮🇳

5

(1)

4 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EXP NO : 03 SHELL SCRIPTING PROGRAM
DATE : 24.08.2020
PROGRAM 1:
SHELL SCRIPT PROGRAM TO CHECK WHETHER A STRING IS PALINDROME:
!#/bin/bash
echo –n “Enter the string:”;
read str1
str=${str1,,}
len=${#str}
palindrome= “true”
let mid=len/2
let j=len-1
for (( i=0; i<$mid; i++ ))
do
left=${str:$i:1}
right=${str:$j:1}
let j=j-1
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:
pf3

Partial preview of the text

Download Shell Scripting Programs: Palindrome Checker and Length Finder and more Lab Reports Microcomputers in PDF only on Docsity!

EXP NO : 03 SHELL SCRIPTING PROGRAM

DATE : 24.08.

PROGRAM 1:

SHELL SCRIPT PROGRAM TO CHECK WHETHER A STRING IS PALINDROME:

!#/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:

PROGRAM 2:

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: