Monday, June 18, 2012

Unix Programs

  1. WAP that accepts user name and reports if user logged in.
echo “Press or enter the user name”
read a
who >userlist
if grep $a userlist
then
echo “user logged on”
else
echo “user not logged on”
fi
  1. WAP that takes a filename as input and checks if it is executable, if not make it executable.
echo “Enter your file name”
read a
if [ ! –e $a ]
then
echo “file not exist”
elif [ ! –x $a ]
then
echo “file is executable”
else
echo “we made it executable”
chmod 777 $a
fi
5.  WAP to take string as command line argument and reverse it.
echo “ Enter the string you want to reverse”
read string
len=`echo –n $string |wc –c`
echo “No. of characteristics : $len”
while test $len –gt 0
do
rev =$rev `echo $string | cut –c $len`
len=`expr $len – 1`
done
echo “The reverse string is : $rev”
6. WAP which displays the following menu and executes the option selected by user:
1. ls
2. pwd
3. ls –l
4. ps -fe
printf “\n\t 1. ls \n\t 2. pwd \n\t 3. ls -l \n\t 4.ps -fe\n\t “
echo “Enter your choice”
read a
case $a in
1) ls ;;
2)pwd ;;
3)ls -l;;
4)ps -fe;;
*)echo “Enter correct value”
esac
7. WAP to print 10 9 8 7 6 5 4 3 2 1 .
for i in 10 9 8 7 6 5 4 3 2 1
do
echo “$i”
done
8. WAP that prompts user for a starting value & counts down from there.
echo “Enter any value for countdown”
read a
while test $a -gt 0
do
echo $a
a=`expr $a – 1`
done
9. WAP that accepts initial value as a command line argument for ex.         If user writes contdown2 12 it should display the value from 12 to 1.
a=$1
while test $a -gt 0
do
echo $a
a=`expr $a – 1`
done
10. WAP that replaces all “*.txt” file names with “*.txt.old” in the current.
for i in *.txt
do
mv “ $i ” “ $i”.old
done

  1. Create a data file called employee in the format given below:
a. EmpCode    Character
b. EmpName   Character
c. Grade           Character
d. Years of experience    Numeric
e. Basic Pay     Numeric
$vi employee
A001           ARJUN       E1      01      12000.00
A006           Anand         E1      01      12450.00
A010           Rajesh         E2      03      14500.00
A002           Mohan         E2      02      13000.00
A005           John             E2      01      14500.00
A009           Denial SmithE2      04      17500.00
A004           Williams      E1      01      12000.00
2.)  Sort the file on EmpCode.
$cut –f1 employee | sort
  1. Sort the file on EmpName.
$cut –f2 employee | sort
  1. Sort the file on
(i) Decreasing order of basic pay
(ii) Increasing order of years of experience.
(i) $cut –f5 employee | sort –r
(ii) $cut –f4 employee | sort
  1. Display the number of employees whose details are included in the file.
wc –l
  1. Display all records with ‘smith’ a part of employee name.
cut –f2 –d “ ” employee | grep ‘^[smith]’ | wc –l
  1. Display all records with EmpName starting with ‘B’.
$cut –f2 employee | grep ‘^[B]’ | wc –l
  1. Display the records on Employees whose grade is E2 and have work experience of 2 to 5 years.
$cut –f3 employee | grep ‘[*2] | cut –f4 employee | grep ‘[2-5]’
  1. Store in ‘file 1’ the names of all employees whose basic pay is between 10000 and 15000.
$cut –f2,5 employee | grep ‘[10000-15000]’ > rec
  1. Display records of all employees who are not in grade E2.
$cut –f3 employee | grep ‘[*1]’
  1. WAP that asks for the user’s favorite color and if it is not ‘red’ informs him that it is wrong answer, waits for 3 sec, clears the screen and asks the question again.
b=red
echo “enter your favorite color : ”
read a
c=`expr $a = $b`
if test $c –eq 1
then
echo “your favorite color is : $a”
else
while test $c –eq 0
do
echo “ your answer is wrong”
sleep 3
clear
echo “enter your favorite color :”
read a
c=`expr $a = $b`
done
echo “your favorite color is : $a”
fi
  1. WAP that reads each line of a target file, then writes the line back to stdout, but with an extra blank line following. This has the effect of a double spacing the file. Include all necessary code whether the script gets the necessary command line argument (a filename), and whether the specified file exists. When the script runs correctly, modify it to triple-space the target file. Finally, write a script to remove all blank lines from the target file, single-spacing it.
if test –e $1 –a –f  $1
then
t=’tty’
exec < $1
while read line
do
echo $line
echo
done
exec > $2
exec < $1
while read line
do
echo $line
echo
echo
done
fi
  1. WAP that echoes itself to stdout, but backwards.
echo “enter your text”
cat > f1
rev f1 | cat > f2
cat f2
  1. Write a script function that determines if an argument passed to it is an integer or a string. The function will return TRUE(0) if passed an integer, and FALSE(1) if passed a string.
[HINT: what does the following expression returns when $1 is not an integer? expr $1 + 0
function check()
{
expr $1 + 0
if [ $? –eq 0 ]
then
echo “argument is integer”
else
echo “not integer”
fi
}
check
7.  A “lucky number” is one whose individual digits add upto 7, in successive additions. For ex. 62431 is a lucky no. (6+4+2+3+1=16, 1+6=7). Find all “lucky numbers” between 1000 and 10000.
echo “lucky number between 1000 to 10000:”
a=1001
while [ $a –lt 10000]
do
n=$a
sd=0
sum=0
while [ $n –gt 0 ]
do
sd=$(( $n % 10 ))
n=$(( $n / 10))
sum=$(( $sum + $sd))
done
n=$sum
sumdig=0
while [ $n –gt 0 ]
do
sd=$(( $n % 10 ))
n=$(( $n / 10))
sumdig=$(( $sumdig + $sd))
done
if [ $sumdig –eg 10 ]
then
n=$sumdig
sd=$(( $n % 10 ))
n=$(( $n / 10))
sumdig=$(( $sumdig + $sd))
fi
if [ $sumdig –eq 7]
then
echo “lucky Number : $a”
fi
a=$(( $a + 1))
done
8. Solve a “quadratic” equation of the form Ax^2+Bx +C=0. Have a script take as arguments the coefficients A, B and C and returns the solutions to four decimal places.
[HINT: pipe the coefficients to bc, using the well known formula, x= (-B + /- sqrt (B^2 – 4AC))/2A].
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main
{
int a, b, c, deter;
float r1,r2;
clrscr();
printf(“Enter coefficients A,B and C (Integers)”);
scanf(“%d%d%d”, &a,&b,&c);
deter=(b*b)-(4*a*c);
if(deter<0)
{
printf(“Roots are imaginary”);
}
if(deter>0)
{
printf(“Roots are real as follows”);
r1=(-b+sqrt(deter))/2*a;
r2=(-b-sqrt(deter))/2*a;
printf(“% .4f \n % .4f”, r1,r2);
}
if(deter=0)
{
printf(“Roots are equal”);
r2=-b/2*a;
printf(“% .4f\n% .4f”,r1,r2);
}
getch();
}
1) Write a shell script to ask your name, program name and enrollment number and print it on the screen.
Echo “Enter your name:”
Read Name
Echo “Enter your program name:”
Read Prog
Echo “Enter your enrollment number:”
Read Enroll
Clear
Echo “Details you entered”
Echo Name: $Name
Echo Program Name: $Prog
Echo Enrolment Number: $Enroll
2) Write a shell script to find the sum, the average and the product of the four integers entered
Echo “Enter four integers with space between”
Read a b c d
Sum =`expr $a + $b + $c + $d`
Avg =`expr $sum / 4`
Dec =`expr $sum % 4`
Dec =`expr \ ($dec \* 1000 \) / 4`
Product =`expr $a \* $b \* $c \* $d`
Echo Sum = $sum
Echo Average = $avg. $dec
Echo Product = $product
3) Write a shell program to exchange the values of two variables
Echo “Enter value for a:”
Read a
Echo “Enter value for b:”
Read b
Clear
Echo “Values of variables before swapping”
Echo A = $a
Echo B = $b
Echo Values of variables after swapping
a = `expr $a + $b`
b = `expr $a – $b`
a = `expr $a – $b`
Echo A = $a
Echo B = $b
4) Find the lines containing a number in a file
Echo “Enter filename”
Read filename
Grep [0-9] $filename
5) Write a shell script to display the digits which are in odd position in a given 5 digit number
Echo “Enter a 5 digit number”
Read num
n = 1
while [ $n -le 5 ]
do
a = `Echo $num | cut -c $n`
Echo $a
n = `expr $n + 2`
done
6) Write a shell program to reverse the digits of five digit integer
Echo “Enter a 5 digit number”
Read num
n = $num
rev=0
while [ $num -ne 0 ]
do
r = `expr $num % 10`
rev = `expr $rev \* 10 + $r`
num = `expr $num / 10`
done
Echo “Reverse of $n is $rev”
7) Write a shell script to find the largest among the 3 given numbers
Echo “Enter 3 numbers with spaces in between”
Read a b c
1 = $a
if [ $b -gt $l ]
then
l = $b
fi
if [ $c -gt $l ]
then
l = $c
fi
Echo “Largest of $a $b $c is $l”
8) Write a shell program to search for a given number from the list of numbers provided using binary search method
Echo “Enter array limit”
Read limit
Echo “Enter elements”
n = 1
while [ $n -le $limit ]
do
Read num
eval arr$n = $num
n = `expr $n + 1`
done
Echo “Enter key element”
Read key
low = 1
high = $n
found = 0
while [ $found -eq 0 -a $high -gt $low ]
do
mid = `expr \( $low + $high \) / 2`
eval t = \$arr$mid
if [ $key -eq $t ]
then
found = 1
elif [ $key -lt $t ]
then
high = `expr $mid – 1`
else
low = `expr $mid + 1`
fi
done
if [ $found -eq 0 ]
then
Echo “Unsuccessful search”
else
Echo “Successful search”
fi
9) Write a shell program to concatenate two strings and find the length of the resultant string
Echo “Enter first string:”
Read s1
Echo “Enter second string:”
Read s2
s3 = $s1$s2
len = `Echo $s3 | wc -c`
len = `expr $len – 1`
Echo “Concatenated string is $s3 of length $len ”
10) Write a shell program to find the position of substring in given string
Echo “Enter main string:”
Read main
l1 = `Echo $main | wc -c`
l1 = `expr $l1 – 1`
Echo “Enter sub string:”
Read sub
l2 = `Echo $sub | wc -c`
l2 = `expr $l2 – 1`
n = 1
m = 1
pos = 0
while [ $n -le $l1 ]
do
a = `Echo $main | cut -c $n`
b = `Echo $sub | cut -c $m`
if [ $a = $b ]
then
n = `expr $n + 1`
m = `expr $m + 1`
pos = `expr $n – $l2`
r = `expr $m – 1`
if [ $r -eq $l2 ]
then
break
fi
else
pos = 0
m = 1
n = `expr $n + 1`
fi
done
Echo “Position of sub string in main string is $pos”
11) Write a shell program to display the alternate digits in a given 7 digit number starting from the first digit
Echo “Enter a 7 digit number”
Read num
n = 1
while [ $n -le 7 ]
do
a = `Echo $num | cut -c $n`
Echo $a
n = `expr $n + 2`
done
12) Write a shell program to find the gcd for the 2 given numbers
Echo “Enter two numbers with space in between”
Read a b
m = $a
if [ $b -lt $m ]
then
m = $b
fi
while [ $m -ne 0 ]
do
x = `expr $a % $m`
y = `expr $b % $m`
if [ $x -eq 0 -a $y -eq 0 ]
then
Echo “gcd of $a and $b is $m”
break
fi
m = `expr $m – 1`
done
13) Write a shell program to check whether a given string is palindrome or not.
Echo “Enter a string to be entered:”
Read str
Echo
len = `Echo $str | wc -c`
len = `expr $len – 1`
i = 1
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”
14) Write a shell program to find the sum of the series sum=1+1/2+…+1/n
Echo “Enter a number”
Read n
i = 1
sum = 0
while [ $i -le $n ]
do
sum = `expr $sum + \ ( 10000 / $i \)`
i = `expr $i + 1`
done
Echo “Sum n series is”
i = 1
while [ $i -le 5 ]
do
a = `Echo $sum | cut -c $i`
Echo -e “$a\c”
if [ $i -eq 1 ]
then
Echo -e “.\c”
fi
i = `expr $i + 1`
done
15) Write a shell script to find the smallest of three numbers
Echo “Enter 3 numbers with spaces in between”
Read a b c
s = $a
if [ $b -lt $s ]
then
s = $b
fi
if [ $c -lt $s ]
then
s = $c
fi
Echo “Smallest of $a $b $c is $s”
16) Write a shell program to add, subtract and multiply the 2 given numbers passed as command line arguments
add = `expr $1 + $2`
sub = `expr $1 – $2`
mul = `expr $1 \* $2`
Echo “Addition of $1 and $2 is $add”
Echo “Subtraction of $2 from $1 is $sub”
Echo “Multiplication of $1 and $2 is $mul”
17) Write a shell program to convert all the contents into the uppercase in a particular file
Echo “Enter the filename”
Read filename
Echo “Contents of $filename before converting to uppercase”
Echo —————————————————-
cat $filename
Echo —————————————————-
Echo “Contents of $filename after converting to uppercase”
Echo —————————————————
tr ‘[a-z]‘ ‘[A-Z]‘ < $filename Echo ————————————————— 18) Write a shell program to count the characters, count the lines and the words in a particular file Echo “Enter the filename” Read file w = `cat $file | wc -w` c = `cat $file | wc -c` l = `grep -c “.” $file` Echo “Number of characters in $file is $c” Echo “Number of words in $file is $w” Echo “Number of lines in $file is $l” 19) Write a shell program to concatenate the contents of 2 files Echo “Enter first filename” Read first Echo “Enter second filename” Read second cat $first > third
cat $second >> third
Echo “After concatenation of contents of entered two files”
Echo —————————————————-
cat third | more
Echo —————————————————-
20) Write a shell program to count number of words, characters, white spaces and special symbols in a given text
Echo “Enter a text”
Read text
w = `Echo $text | wc -w`
w = `expr $w`
c = `Echo $text | wc -c`
c = `expr $c – 1`
s = 0
alpha = 0
j = ` `
n = 1
while [ $n -le $c ]
do
ch = `Echo $text | cut -c $n`
if test $ch = $j
then
s = `expr $s + 1`
fi
case $ch in
a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z) alpha=`expr $alpha + 1`;;
esac
n = `expr $n + 1`
done
special = `expr $c – $s – $alpha`
Echo “Words = $w”
Echo “Characters = $c”
Echo “Spaces = $s”
Echo “Special symbols = $special”
24) Write a shell program to find factorial of given number
Echo “Enter a number”
Read n
fact = 1
i = 1
while [ $i -le $n ]
do
fact = `expr $fact \* $i`
i = `expr $i + 1`
done
Echo “Factorial of $n is $fact”
25) Write a shell script to find the average of the numbers entered in command line
n = $#
sum = 0
for i in $*
do
sum = `expr $sum + $i`
done
avg = `expr $sum / $n`
Echo “Average=$avg”
26) Write a shell script to sort the given numbers in descending order using Bubble sort
Echo
i = 1
k = 1
Echo “Enter no. of integers to be sorted”
Read n
Echo “Enter the numbers”
while [ $i -le $n ]
do
Read num
x[$k] = `expr $num`
i = `expr $i + 1`
k = `expr $k + 1`
done
x[$k] = 0
k = 1
Echo “The number you have entered are”
while [ ${x[$k]} -ne 0 ]
do
Echo “${x[$k]}”
k = `expr $k + 1`
done
k = 1
while [ $k -le $n ]
do
j = 1
while [ $j -lt $n ]
do
y = `expr $j + 1`
if [ ${x[$j]} -gt ${x[$y]} ]
then
temp = `expr ${x[$j]}`
x[$j] = `expr ${x[$y]}`
x[$y] = `expr $temp`
fi
j = `expr $j + 1`
done
k = `expr $k + 1`
done
k = 1
Echo “Number in sorted order…”
while [ ${x[$k]} -ne 0 ]
do
Echo “${x[$k]}”
k = `expr $k + 1`
done
27) Write a shell program to find the sum of all the digits in a given 5 digit number
Echo “Enter a 5 digit number”
Read num
sum = 0
while [ $num -ne 0 ]
do
r = `expr $num % 10`
sum = `expr $sum + $r`
num = `expr $num / 10`
done
Echo “sum = $sum”
28) Write a shell script to generate fibonacci series
Echo “how many fibonacci numbers do u want “
Read limit
a = 0
b = 1
d = 1
Echo “————————————————————-”
Echo -n $a
Echo -n ” “
while test $d -le $limit
do
c = `expr ${a} + ${b}`
Echo -n $c
Echo -n ” “
b = $a
a = $c
d = `expr $d + 1`
done
29) Shell Script to check whether given year is leap year or not
Echo -n “Enter the year(yyyy) to find leap year :- “
Read year
d = `expr $year % 4`
b = `expr $year % 100`
c = `expr $year % 400`
if [ $d -eq 0 -a $b -ne 0 -o $c -eq 0 ]
then
Echo “year is leap year”
else
Echo “not leap year”
fi
30) Shell Script to print alternate digit when a 7 digit number is passed
Echo -n “Enter a 7 digit number:- “
Read number
len = `echo $number | wc -c`
flag = 1
while test $flag -le $len
do
Echo $number | cut -c$flag
flag = `expr $flag + 2`
done
31) Shell script to find average of number at given command line
total = 0
count = $#
for i #or u can append ( in $*) to get same result.
do
total = `expr $total + $i`
done
avg1 = `expr $total / $count`
avg2 = `expr $total % $count`
avg2 = `expr $avg2 \* 100 / $count`
Echo “The Average is :- $avg1.$avg2″
32) Shell Script to reverse a inputted string and show it
Echo -n “enter the string u want to reverse:-”
Read string
len = `Echo -n $string |wc -c`
Echo “no of character is:- $len”
while test $len -gt 0
do
rev = $rev`Echo $string |cut -c $len`
len = `expr $len – 1`
done
Echo “the reverse string is:-$rev “
33) Shell script to find occurrence of particular digit in inputted number
Echo -n “enter any number:-”
Read number
Echo -n “which digit number do u want to count:-”
Read digit
len = `echo -n $number |wc -c`
Echo “the length of number is:-$len”
count = 0
while test $len -gt 0
do
flag = `Echo -n $number |cut -c $len`
if test $flag -eq $digit
then
count = `expr $count + 1`
fi
len = `expr $len – 1`
done
Echo “|$digit| occurred |$count| times in number ($number)”
34) Shell Script to find whether number given is even or odd
Echo -n “enter any integer number to find even and odd :-”
Read number
rem = `expr $number % 2`
if test $rem -eq 0
then
Echo “number is even”
else
Echo “number is odd”
fi
35) write shell script to generate fibonacci series
#!/bin/bash
#shell script to generate fibonacci series
echo “how many fibonacci numbers do u want “
read limit
a=0
b=1
d=1
echo “————————————————————-”
echo -n $a
echo -n ” “
while test $d -le $limit
do
c=`expr ${a} + ${b}`
echo -n $c
echo -n ” “
b=$a
a=$c
d=`expr $d + 1`
done
36) write shell script to find wheather a particular year is a leap year or not
#!/bin/bash
#shell script to find wheather a particular year is a leap year or not
echo -n “Enter the year(yyyy) to find leap year :- “
read year
d=`expr $year % 4`
b=`expr $year % 100`
c=`expr $year % 400`
if [ $d -eq 0 -a $b -ne 0 -o $c -eq 0 ]
then
echo “year is leap year”
else
echo “not leap year”
fi
37) write shell script to print alternate digits when a 7 digit number is passed as input
#!/bin/bash
#shell script to print alternate digits when a 7 digit number is passed as input
echo -n “Enter a 7 digit number:- “
read number
len=`echo $number | wc -c`
flag=1
while test $flag -le $len
do
echo $number | cut -c$flag
flag=`expr $flag + 2`
done
38) write shell script to find average of numbers given at command line
#Tue May 28 11:12:41 MUT 2002
total=0
count=$#
for i #or u can append ( in $*) to get same result.
do
total=`expr $total + $i`
done
avg1=`expr $total / $count`
avg2=`expr $total % $count`
avg2=`expr $avg2 \* 100 / $count`
echo “The Average is :- $avg1.$avg2″
39) write shell script to find wheather a given word is palindrome or not
#Sun Jun 9 12:06:14 MUT 2002 –By Mukesh
clear
echo -n “enter the name :-”
read name
len=`echo -n $name | wc -c`
echo “Length of the name is :-”$len
while [ $len -gt 0 ]
do
rev=$rev`echo $name | cut -c$len`
len=`expr $len – 1`
done
echo “Reverse of the name is :-”$rev
if [ $name = $rev ]
then echo “It is a palindrome”
else
echo “It is not a palindrome”
fi
40) write shell script to reverse a inputed string and show it.
#!/bin/bash
#shell script to reverse a inputed string and show it.
echo -n “enter the string u want to reverse:-”
read string
len=`echo -n $string |wc -c`
echo “no of character is:- $len”
while test $len -gt 0
do
rev=$rev`echo $string |cut -c $len`
len=`expr $len – 1`
done
echo “the reverse string is:-$rev “
41) write shell script to count occurence of a perticular digit in inputted number.
#!/bin/bash
#shell script to count occurence of a perticular digit in inputted number.
echo -n “enter any number:-”
read number
echo -n “which digit number do u want to count:-”
read digit
len=`echo -n $number |wc -c`
echo “the length of number is:-$len”
count=0
while test $len -gt 0
do
flag=`echo -n $number |cut -c $len`
if test $flag -eq $digit
then
count=`expr $count + 1`
fi
len=`expr $len – 1`
done
echo “|$digit| occured |$count| times in number ($number)”
42) write shell script to find even or odd.
#!/bin/bash
#shell script to find even or odd.
echo -n “enter any integer number to find even and odd :-”
read number
rem=`expr $number % 2`
if test $rem -eq 0
then
echo “number is even”
else
echo “number is odd”
fi


Monday, June 11, 2012

UNIX – SHELL PROGRAMMING –LAB



1.  Write a shell script to accept even no of file names. Suppose 4 file names are supplied then the first file should get copied into the second file the third file should get copied into the fourth file and so on. If odd no. of file names is supplied then no copying should take place and error message should be displayed?

 
CheckNo=`expr $# % 2`
    if [ $CheckNo -ne 0 ]
    then
            echo "Enter Even Number Of Arguments."else
            cnt=1
            while [ $cnt -lt $# ]
            do
                    cp $1 $2
                    shift
                    shift
                    cnt=`expr $cnt + 2`
            done
    fi
2.  Write a script to list the files which have having read & execute permissions in the given directory?
3.  Write a shell program to find factorial of  given number using command line   ?
4.  Write a shell script to print the contents of a file only some range of lines. The starting and ending line numbers should be passing through command line arguments?
if [ -f $3 ]
then
if [ $1 -lt $2 ]
then
sed -n ' '$1','$2' 'p' ' $3
fi
fi
 
5   Write a shell script to take the backup of all C programs in your account on every Friday at 5 pm?
6.  Compress your home directory and copy to /tmp directory with different utilities? Then uncompress your home directory in /tmp by any one utility?
7. Write a shell script to reverse the digits of a given number.

if [ $# -ne 1 ]
then
echo "Usage: $0 number"
echo " I will find reverse of given number"
echo " For eg. $0 123, I will print 321"
exit 1
fi

n=$1
rev=0
sd=0

while [ $n -gt 0 ]
do
sd=`expr $n % 10`
rev=`expr $rev \* 10 + $sd`
n=`expr $n / 10`
done
echo "Reverse number is $rev"
8. Write a shell script to reverse the digits of a given number
9. Write a shell script to generate the factorial of a given number entered through keyboard.
10. Write a shell script to print the first even and odd numbers less than 30
11. Write a shell script to copy the source file to the target file.
12. Write a shell script which will accept different numbers and find sum of its digit.

if [ $# -ne 1 ]
then
echo "Usage: $0 number"
echo " I will find sum of all digit for given number"
echo " For eg. $0 123, I will print 6 as sum of all digit (1+2+3)"
exit 1
fi
n=$1
sum=0
sd=0
while [ $n -gt 0 ]
do
sd=`expr $n % 10`
sum=`expr $sum + $sd`
n=`expr $n / 10`
done
echo "Sum of digit for numner is $sum"


13. Write a shell script to find the mode of a file in a directory.
14. Write a menu driven program to display a menu of options and depending upon the user’s choice execute the associated command.
15. Write a shell script to display first ten positive numbers using until loop.
16. Write a shell script to Implement If-Else Ladder (Unix Program)
17.Write a shell script to link the files such that modification made by one file should be applicable to the linked file?
18.Write a script to determine whether given file is exists or not, filename is supplied as command line arguments and also display the file permissions if it exist.



19. Write a shell script for the following
     i) Redirecting the standard input
    ii) Redirecting the standard  output
    iii) Redirecting the standard error using switch case menu driven, & it should continue as long as user wants
20. Execute a command such that whenever we give NTTF <filename> it should create a directory and when ever we give REM <filename> it should delete the directory?
21. Write a shell script which displays the list of all files in the given directory
22. Write a shell script which counts the number of lines and words present in a given file.
23. Write a shell script to generate a multiplication table
24. Write a shell script that copies multiple files to a directory.
25. Write A shell script that takes a command –line argument and reports on whether it is directry ,a file,or something else
26. Write a shell script that computes the gross salary of a employee
27. Write a script to take backup at 10 am every day for selected file?
28. Execute any two commands at a time and store both the output in different files?
29. Write a program to display a message at 10:10am today and that should be sent to a mail?
30. How to make schedule for creating backup of user program for a particular user from root account?
31.  Write the shell script for the following operations using case
a.            Display all the running processes status in detail
b.            Start a process in the background for manual page for ls
c.             Display the current background process
d.            Terminate the background  process
32.  Write a shell script to add three float values using command line arguments
33. Write the shell script for List the filenames for which the 3rd character is not a digit?
34. Write a shell script to wish the user depending on his login time i.e to wish ‘good morning’, ‘good afternoon’, and ‘good evening’?

th=`date | cut –c12-13`
if [ $th –lt 12 ]
then
mesge=”good morning $LOGNAME have a nice day!”
fi
if [ $th –gt 12 –a $th –lt 16 ]
then
mesge=”good afternoon $LOGNAME”
fi
if [ $th –gt 16 –a $th –lt 20 ]
then
mesge=”good evening”
fi
echo –e “$mesg”
35. Write a shell script to show the file content in capitals for selected file by using command line arguments?
36. Write a shell script to find the given year is leap year or not?
37. write the shell script to find out the all ordinary files in your current working directory that are writable?
38. Write a script to find biggest among three entered numbers using command line arguments?

if [ $# -ne 3 ]
then
echo "$0: number1 number2 number3 are not given" >&2
exit 1
fi
n1=$1
n2=$2
n3=$3
if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
then
echo "$n1 is Bigest number"
elif [ $n2 -gt $n1 ] && [ $n2 -gt $n3 ]
then
echo "$n2 is Bigest number"

elif [ $n3 -gt $n1 ] && [ $n3 -gt $n2 ]
then
echo "$n3 is Bigest number"
elif [ $1 -eq $2 ] && [ $1 -eq $3 ] && [ $2 -eq $3 ]
then
echo "All the three numbers are equal"
else
echo "I can not figure out which number is biger"
fi

39. write a shell script to  Check whether the given character is small or capital?
40 Write a script to print entered no in descending order by using while loop
(eg : 5, 4, 3, 2, 1 ) using command line arguments?
41. Read a character from user if it is between A-D (print mesg: “entered character between A-D”) same way check for M-P and Q-V and display respective message?
42. Write a script for addition, subtraction, multiplication and division using command line arguments?
43. Write a script to see current date & time, username, home directory, default shell and current working directory using case statement & it should continue as long as user wants?

echo "Hello, $LOGNAME"
echo "Current date is `date`"
echo "User is `who i am`"
echo "Current direcotry `pwd`"
44. Write a shell program for making directory if that directory exists then print the mesg it’s already exists else create a directory by using command line arguments?
45. Write a shell script to check whether given name is a directory or file by using command line arguments?
46. Write a shell script to print sum of digits for entered no?
47. Write a shell script to accept date (dd,mm,yy) and increment day by 1 and check the condition and display the date (eg:20/12/2009)
48. Write a shell script to accept student information like name, class and 3 subject marks. Calculate the total and average. Result will be displayed based on average .if avg >=80 and avg <=90 (Distinction), avg >=60 and avg<=80 (First class), avg>=35 and avg<=59 (Second class), avg<35 (Fail)
49.   Write a shell script for the following using case statement
i)             Display the user who are all logged in system
ii)            Display the terminal type of the user
iii)           Compress the file,file name should get it from the user at runtime
iv)           Display the content of the compressed file
v)            Create the hardlink and softlink the filename should get it  from the user
vi)           Display the longlist of the hardling and softlink file
50.    Write a c program to find weather the given number is palindrome or not