Академический Документы
Профессиональный Документы
Культура Документы
5. Wap by using grep command with both logical operators && and ||.
grep -e 'hod \| hi' compsc
grep -e 'study .* student' compsc
Combine the two files in the form of register number followed by name
Print the specified number of lines of a file from start to end of the file
Create a file
Rename a file
Create a file
Rename a file
18. Write script to find out biggest number from given three numbers. Numbers are supplies as
command line argument. Print error if sufficient arguments are not supplied.
if [ $# -ne 3 ]
then
echo "Please give 3 command line arguments"
exit 1;
fi
if [ $1 -gt $2 ] && [ $1 -gt $3 ]
then
19. How to write shell script that will add two numbers, which are supplied as command
line argument, and if this two numbers are not given show error and its usage.
if [ $# -ne 2 ] ; then
echo -e " please provide correct number of arguments"
else
# $1 is first argument and $2 is second .
echo " sum of $1 + $2 is `expr $1 + $2` "
fi
20. Find a given file and show its permission and last modified Date 04.03.2016
21. Write a shell script to check whether a given file is exist or not?
22. Enter a number of names and sort them then display on the screen.
23. Write a Shell program to check the given number is even or odd
echo -n "Enter numnber : "
read n
rem=$(( $n % 2 ))
if [ $rem -eq 0 ]
then
echo "$n is even number"
else
echo "$n is odd number"
fi
24. Write a Shell program to check the given year is leap year or not
echo "Enter the year in 4 digits"
read a
if test `expr $a % 4` -eq 0
then
if test `expr $a / 100 ` -ne 0 -o `expr $a % 400` -eq 0
then
echo "The year is a leap year"
fi
else
echo "the year is not a leap year"
fi
25. Write a Shell program to find the area and circumference of a circle
echo "Enter the radius of the circle"
read r
pi=3.14
c=$(echo "scale=2;$pi * ($r * $r)" | bc)
echo "The area of cirlce is"
echo $c
d=$(echo "scale=2;$pi * (2 * $r)" | bc)
echo "The circumference is =$d"
26. Write a Shell program to check the given integer is prime or not
27. Write a Shell program to find the sum of square of individual digits of a number
echo "Enter the number"
read n
j=$n
s=0
while [ $j -gt 0 ]
do
r=`expr $j % 10`
j=`expr $j / 10`
s=`expr $s + $r \* $r`
done
echo "sum of square of the number is : $s"
28. Write a Shell program to find the largest among three numbers
echo Enter 3 numbers with spaces in between
read a b c
l=$a
if [ $b -gt $l ]
then
l=$b
fi
if [ $c -gt $l ]
then
l=$c
fi
echo Lagest of $a $b $c is $l
s=1
for(( i=1; i<=$n; i++ ))
do
s=$((s * i))
done
echo "The factorial is = $s"
31. Write a Shell program to swap the two integers ( i ) with temporary variable and
without using temporary variable.
echo "Enter two numbers to swap"
read a
( ii )
read b
echo "before swap"
echo "a=$a"
echo "b=$b"
temp=$a
a=$b
b=$temp
echo "after swap"
echo "a=$a"
echo "b=$b"
32. Write a Shell program to find the sum of all numbers between 50 and 100, which are
divisible by 3 and not divisible by 5.
echo "the sum of numbers from 50 to 100 which are divisible bye 3 but not divisible by 5"
s=0
for(( i=50; i<=100; i++ ))
do
j=$i
if test `expr $j % 3` -eq 0 -a `expr $j % 5` -ne 0
then
s=`expr $s + $j`
fi
done
echo "The sum of numbers is: $s"
33. Write script to see current date , time , shell and directory.
echo "Hello, $LOGNAME"
echo "Current date is `date`"
echo "User is `who i am`"
echo "Current direcotry `pwd`"
34. How to calculate 5.12 + 5.2 real number calculation at dollar prompt in shell.
35. How to perform real number calculation in shell script and store the result in third variable,let
say a=5.66, b=8.67 , c=a+b?
a=5.66
b=8.67
c=`echo $a + $b | bc`
echo "$a + $b = $c"
25. Write a Shell program to check the given integer is prime or not
echo "Enter a number: "
read num
i=2
f=0
while [ $i -le `expr $num / 2` ]
do
if [ `expr $num % $i` -eq 0 ]
then
f=1
fi
i=`expr $i + 1`
done
if [ $f -eq 1 ]
then
echo "The number is composite"
else
echo "The number is Prime"
fi