Unix Lab Programs: 1) Unix Shell Program To Calculate Odd and Even Numbers in Given Range
1) A shell script to calculate odd and even numbers in a given range using a while loop.
2) A shell script to find the largest of 3 numbers input by the user.
3) A shell script to check if a given string is a palindrome by reversing the string and comparing it to the original.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
46 views
Unix Lab Programs: 1) Unix Shell Program To Calculate Odd and Even Numbers in Given Range
1) A shell script to calculate odd and even numbers in a given range using a while loop.
2) A shell script to find the largest of 3 numbers input by the user.
3) A shell script to check if a given string is a palindrome by reversing the string and comparing it to the original.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
UNIX LAB PROGRAMS
1) Unix Shell Program to calculate odd and even numbers in given
range echo enter n value as range to calculate odd and even numbers. read n i=1 while [ $i -le $n ] do if [ `expr $i % 2` -eq 0 ] then echo even=$i else echo odd=$i f i=`expr $i + 1` done 2) Write Shell Script program to find the biggest of 3 numbers. echo Enter 3 numbers with spaces in between read a b c l=$a if [ $b -gt $l ] then l=$b f if [ $c -gt $l ] then l=$c f echo Lagest of $a $b $c is $l
3) Code for Write a shell program to check whether a given string
is palindrome or not echo -n input string read num length =`expr length $num` while [ $length ne 0 ] do b=$b ` expr substr $no $length 1` length= `expr $length 1` done echo Reverse String is $b if [ $num=$b ] then echo Is Polindrome else echo Is not Polindrome f
4) Write a shell script to change extension of an existing file.
echo "Enter frst fle name: " read f1 if [ -f $f1 ] then echo "Enter new extention: " read e cp ${f1} ${f1}.$e echo $f1"."$e" fle is created"else echo "File not Exist " f
5) Reverse rows and columns of matrix using Shell Script code
echo "Enter Number of rows" read r echo "Enter Number of columns" read c i=0 echo "Enter elements" until [ $i -eq `expr $r \* $c` ] do read a[$i] i=`expr $i + 1` done i=0 ; k=0 echo "Transpose of a Matrix" until [ $i eq $c ] do j=0; until [ $j eq $r ] do n= `expr $j \* $c` m= `expr $n + $i b[$k]=${a[$m]} echo "${b[$k]} \t" k=`expr $k + 1` j=`expr $j + 1` done i=`expr $i + 1` echo "\n" done