Date: Prg. No:1

Write a shell script to find whether a given string is palindrome or not

echo "Enter a string" read str len=`expr $str | wc -c` while [ $len -ne 0 ] do str1=`expr $str | cut -c $len` len=`expr $len - 1` rev=`echo $rev$str1`

done echo "Reversed string is $rev" if [ $str = $rev ] then echo $str is a palindrome else echo $str is not a palindrome fi

OUTPUT [m09mc21@linuxserver m09mc21]$ sh palindrome Enter a string madam Reversed string is madam madam is a palindrome

UNIX PROGRAMMING LAB Date: Prg. No:2 Write a shell script that displays Good Morning. hour=`date | cut -c 12-13` if [ $hour -ge 0 -a $hour -lt 12 ] then echo "Good morning" elif [ $hour -ge 12 -a $hour -lt 16 ] then echo "Good afternoon" elif [ $hour -ge 16 -a $hour -lt 18 ] then echo "Good evening" else echo "Good night" fi OUTPUT [m09mc21@linuxserver m09mc21]$ sh lab2 Good evening . Good Afternoon or Good Evening depending upon the time the user logs in.

UNIX PROGRAMMING LAB Date: Prg. No:3 Write a shell program to accept a directory name and count the number of subdirectories in the given directory echo "enter a directory name" read dir if [ ! -d $dir ] then echo "Enter a valid directory" else cd $dir count=0 for i in `ls` do if [ -d $i ] then count=`expr $count + 1` fi done echo "The number of subdirectories in $dir is $count" fi OUTPUT echo "enter a directory name" read dir [m09mc21@linuxserver m09mc21]$ sh lab3 enter a directory name lab The number of subdirectories in lab is 1 .

UNIX PROGRAMMING LAB Date: Prg.1 m09mc21 m09mc21 -rw-rw-r-.1 m09mc21 m09mc21 0 Aug 10 17:56 a 0 Aug 10 17:56 b [m09mc21@linuxserver m09mc21]$ sh lab4 Enter directory name: lab deleting a deleting b . No:4 Write a shell script to delete zero byte files in the present working directory echo "Enter directory name:" read dir if [ ! -d $dir ] then echo "Enter valid directory name" else cd $dir for i in `ls -s` do t=`ls -l $i | cut -c 42` if [ $t -eq 0 ] then echo "deleting $i" rm $i fi done fi OUTPUT [m09mc21@linuxserver lab]$ ls -l total 20 -rw-rw-r-.

UNIX PROGRAMMING LAB Date: Prg No:5 Write a shell script that accepts a filename.$start` d=`expr $d -1` a=`expr $start + 1` tail +$a $name | head -$d else echo "starting line number must be lessthan ending line number" fi fi OUTPUT [m09mc21@linuxserver m09mc21]$ sh lab5 Enter the file name: leap Enter the starting line number 4 Enter the ending line number 6 then echo "$year is not leap year" else echo "$year is leap year" fi . echo "Enter the file name:" read name if [ ! -f $name ] then echo "Enter valid file name" else echo "Enter the starting line number" read start echo "Enter the ending line number" read end if [ $start -lt $end ] then d=`expr $end . starting and ending line numbers as arguments and displays all the lines between the given line numbers.

if [ $# -ne 1 ] then echo "Enter argument" elif [ -d $1 ] then echo "$1 is a directory" elif [ -f $1 ] then echo "$1 is a file" else echo "$1 is neither a file nor directory" fi OUTPUT [m09mc21@linuxserver m09mc21]$ sh lab6 Enter argument [m09mc21@linuxserver m09mc21]$ sh lab6 leap leap is a file [m09mc21@linuxserver m09mc21]$ sh lab6 lab lab is a directory .UNIX PROGRAMMING LAB Date: Prg No: 6 Write a shell script that takes a command line argument and reports on whether it is a directory or a file.

UNIX PROGRAMMING LAB Date: Prg. No: 7 Write a shell script using function and eval .

UNIX PROGRAMMING LAB Date: Prg.NET:" read net tot=`echo $c + $cpp + $cobol + $java + $net |bc` per=`echo $tot / 5 | bc` if [ $per -ge 75 ] then grade="Distinction" elif [ $per -ge 60 || $per -le 74 ] then grade="First Class" elif [ $per -ge 50 || $per -le 59 ] then grade="Second Class" elif [ $ per -ge 40 || $per -le 49 ] then grade="Third Class" else grade="Fail" fi tput clear echo "------------------------------------" echo " REPORT " echo "------------------------------------" echo "Name : $name" echo "Branch :$bname" echo "C C++ COBOL JAVA .NET TOTAL" echo "$c $cpp $cobol $java $net $tot" echo "------------------------------------" . No: 10 Write a menu driven shell script to generate report card echo "Enter the name of the student:" read name echo "Enter Branch:" read bname echo "Enter marks scored in C Programming:" read c echo "Enter marks scored in C++:" read cpp echo "Entr marks scored in COBOL:" read cobol echo "Enter marks scored in JAVA:" read java echo "Enter marks scored in .

NET TOTAL 100 90 95 100 100 485 PERCENTAGE: 97 CLASS : Distinction --------------------------------------------------------- .UNIX PROGRAMMING LAB OUTPUT --------------------------------------------------------REPORT ---------------------------------------------------------Name : Amar Branch : BTech C C++ COBOL JAVA .

202.943  .3.7 7.  &!# #  &%!&%   #! #%  .    ' %% %      !#% $$893.%0.

Sign up to vote on this title
UsefulNot useful