Code In Tech - The Ultimate World of Computer Technology

Showing posts with label Operating system. Show all posts
Showing posts with label Operating system. Show all posts

Thursday, 7 June 2012

Shell script to fine area and perimeter

SOURCE CODE:
 
echo "Enter the length of the rectangle"
echo "Enter the length of the rectangle"
read l
echo "Enter the breadth of the rectangle"
read b
echo "Enter the side of the square"
read a
areaR=`expr $l \* $b`
periR=`expr $l \* 2 + $b \* 2`

Shell script for multiplication table

SOURCE CODE:

echo "Enter the number:"
read i
echo "$i table"
j=1
while [ $i -le 10 ]
do
l=`expr $j \* $j = $l`
echo "$j *$i = $l"
j=`expr $j + 1`
done

Tuesday, 5 June 2012

Shell script for swapping two values

SOURCE CODE:

echo "Enter first value:"
read a
echo "Enter second value:"
read b
temp=$a
a=$b
b=$temp
echo "The swapped value is:"
echo "First value = $a"
echo "Second value = $b"

Shell script to find simple interest

SOURCE CODE:

echo " Enter the principle value: "
read p
echo " Enter the rate of interest:"
read r
echo " Enter the time period:"
read t
s=`expr $p \* $t \* $r / 100`
echo " The simple interest is "
echo $s

Shell script to find Leap Year

SOURCE CODE:

echo "Enter the year :"
read year
d =`expr $year % 4'
if [ d -eq 0 ]
then
echo “$Given year is a leap year”
else
echo "$Given year is not a leap year”
fi

Monday, 4 June 2012

Shell script to greet user according to time.

SOURCE CODE:

hr=`date "+ %H"`

echo "Hour : " $hr

if test $hr -lt 12

then

echo "Good Morning User "

elif test $hr -gt 16


Shell script to display the digits in odd position from the given five digit no.

SOURCE CODE:

echo “Enter the string of the five nos.”
read n
i=1
a=” ”
while [ $i –le 5]
do
     o=`echo $n | cut –c $i`
     s=$s$a$o
i=`expr $i + 2`
    done

Shell script to read name and price of article and calculate net price with discount as follows.>If price less than 100 then 10% discount If price >= 100 then 20% discount

SOURCE CODE:

echo “Enter the article’s name:“
read name
echo “Enter the  price:”
read p
if [ $p –lt 100 ]
then
     t=`expr $p \* 10`
     r=`expr $t / 100`
     n=` expr $p - $r`
else
    

Shell script for interactive file handling program

SOURCE CODE:

echo "1. To copy a file"
echo "2. To rename a file"
echo "3. To remove a file"
echo "4. To compare two file"
read ch
case "$ch" in
1)
ls
echo "Enter existing file name :"
read file1

Shell script to Create a calculator by case system

SOURCE CODE:

echo “Enter the values :”

echo “x:”
read x
echo “y:”
read y

echo “1: Addition”
echo “2: Subtraction”
echo “3: multiplication.”
echo “4: Division.”

Write a shell script. to remove files having following properties…(i) Remove all files having exactly 3 characters. (ii) Remove all files having specified extension. (iii) Remove all files having Name starting with lower case letters and ending with digits.

SOURCE CODE:
echo “1: File having only 3 char."
echo “2: File having specified extension.”
echo “3: File having name starting with lower case letters and ends at digits.”

echo “Enter your choice:”
read c
if [ $c = 1 ]
then
     echo “Files are…”
     ls ???

Saturday, 12 May 2012

Shell script to find a max no out of three nos using else if & and operator.

SOURCE CODE:

echo “Enter the three nos.”
read a
read b
read c
if [ $a –gt $b –a $a –gt $c ]
then
     echo $a “is maximum no.”
elif [ $b –gt $a –a $b –gt -$c ]
then
     echo $b “maximum no.”
else
     echo $c “is maximum no.”

fi

Shell script to concate two strings and find the length of resulting string.

SOURCE CODE:

echo “Enter 1st string:”
read s1
echo “ Enter 2nd string”
read s2

s=$s1$s2
l =`expr length $s`
 echo “string:” $s “ length :” $l

Shell script to reverse the given no.

SOURCE CODE:

echo  “Enter the no.:”
read n
l =`expr length $n `
a=1
d=$n
while [ $a –le $l ]
do
     m=`expr $d % 10`
     d=`expr $d / 10`
     s=$s$m
     a=`expr $a + 1`
done
echo $s

Shell script to sum of digits of a given no.

SOURCE CODE:

echo “Enter the no:”
read n
l =`expr length $n `
a=1
while [ $a –le $l ]
do
     r=`expr $n | cut –c $a`
     s=`expr $s + $r`
     a=`expr $a + 1`
done
echo “Ans:“ $s

Shell script to reverse a string.

SOURCE CODE:

echo “Enter the string”
read str
l=`expr length $str`
a=1
r=$l
while [ $a –le $r ]
do
     s=`expr $str | cut –c $l`
     l=`expr $l – 1`
     a=`expr $a + 1`

Shell script to find the max. no out of given five nos.

SOURCE CODE:

echo “Enter five nos.”
i=0
b=0
t=0
while [ $i –lt 5 ]
do
     read a
     b= $t
     if teat $b –lt $a
     then

Shell script to find the length of string, if it’s greater than 10 then print string is greater than 10 else less than 10.

SOURCE CODE:

echo “Enter the string:“
read str
l =`expr length $str`
if [ $l –lt 10 ]
then
     echo “String is less than 10”
fi
if [ $l –eq 10 ]
then
     echo “String is equal to 10”
fi

Shell script to print the fibonaci series up to given no.

SOURCE CODE:

echo “Enter the no.:“
read n
i=0
j=1
k=1
echo $i
while [ $j –le -$n ]
do
     echo $k
     k=`expr $j + $i`

Shell script to check whether the given no. is Armstrong or not

SOURCE CODE:

echo “ Enter the no.”
read n
l =`expr length $n`
i=1
d=1
while [ $i –le $l ]
do
     r=`expr $n | cut –c $i`
     i=`expr $i + 1`
     m=`expr $r \* $r \* $r`