Vous êtes sur la page 1sur 35

Q10.

VI EDITOR, INODE
AND LINKS
Q11. CREATING
ARCHIVES

GZIP,GUNZIP,BZIP2,BUNZIP2,TAR
Q 12 Practice
Exercise 3

1. Write a shell script to print addition of two numbers


2. Write a shell script to print subtraction of two numbers
3. Write a shell script to print multiplication of two numbers
4. Write a shell script to print division of two numbers
5. Write a shell script to perform all the functions together over
two numbers entered by user.
1-5.)

6. Perform following function by shell script : D=b+c/a

#!/bin/bash
hello()
{ a=`expr $c / $a`
D=`expr $b + $a`
echo "$D"
}
a=2
b=15
c=2
echo "a=$a b=$b c=$c"
hello

7. Perform following function by shell script: D=(b+c/a) * b

#!/bin/bash
hello()
{ a=`expr $c / $a`
e=`expr $b + $a`
D=`expr $e \* $b`
echo "$D"
}
a=3
b=10
c=9
echo "a=$a b=$b c=$c"
hello

8. Write the shell script to calculate average & percentage of


marks entered by user.
#!/bin/bash
m1=84.5
m2=75.6
m3=50

sum=`echo $m1 + $m2 + $m3 | bc -l`


avg=`echo $sum / 3 | bc -l`
echo "percentage= $sum"
echo "average= $avg"

9. Write a shell script to print all the users who have currently
logged in

#!/bin/bash
echo "the users logged in are ";w

10. Write a shell script to display only the size of files from the
current working directory

#!/bin/bash
ls -lah|awk '{print $5,$9}'|column –t

Q 13. Practice
Exercise 4
1. Write a shell script to create a directory and files and
subdirectories

#!/bin/bash
mkdir dummy
mkdir -pv dummy/demo/file.txt

2. To find the largest of two numbers

#!/bin/bash
echo "enter two numbers"
read a b
if [ "$a" -gt "$b" ] #(($a>$b))
then
echo "$a is greater"
else
echo "$b is greater"
fi

3. To check whether a number is even or odd


#!/bin/bash
echo "enter a number"
read a
if(($a%2 == 0))
then
echo "$a is even"

else
echo "$a is odd"
fi

4. To print the values of environment variables

#!/bin/bash
echo "enter a environment variable in caps";read a
printenv $a

5. To extract certain values from environment variable path

#!/bin/bash
Str=`echo $path`
F=${str:0:7}
Echo $F

6. To find largest of three given number.

#!/bin/bash
echo "enter 3 number"
read a b c
if [ $a -gt $b -a $a -gt $c ];
then
echo "$a is greatest"
elif [ $b -gt $c ];
then
echo "$b is greatest"

else
echo "$c is greatest"

fi

7. To greet the user according to the week of the day.

#!/bin/bash
var=$(date +%A)
echo $var
case "$var" in
("Monday") echo "Oh! its monday";;
("Tuesday") echo "3 more days to go";;
("Wednesday") echo "eagerly waiting";;
("Thursday") echo "just day left for an adventure";;
("Friday") echo "pack your bag";;
("Saturday") echo "fly away";;
("Sunday") echo "last day to have fun";;
esac

8. To display the number of vowels and consonants in a string


#!/bin/bash
echo "enter a word"
read a

vowels=$(echo $a|sed 's/[^aeiou]//g')


consonants=$(echo $a |sed 's/[aeiou]//g')

echo "${#vowels} vowels"


echo "${#consonants} consonants"

9. To perform arithmetic operation using case-- -- esac.

#!/bin/bash
echo "enter two numbers"
read a b
echo "enter your choice: \n 1.add \n 2.subtract \n 3. multiply \n 4. divide"
read c

case $c in
1) echo `expr $a + $b` ;;
2) echo `expr $a - $b` ;;
3) echo `expr $a \* $b` ;;
4) echo `expr $a / $b` ;;
esac

10. To count words, lines and characters in a file

#!/bin/bash
echo "enter filename or directory"
read a
wc -lwm "$a"

11. To find out which shell you are working in.


#!/bin/bash
echo $SHELL

12. To show the output of who command sorted on 3 rd column

#!/bin/bash
who|sort -k 3,3n

13. To check whether the year entered is leap or not.

#!/bin/bash
echo "enter a year"
read a
while [ $a -ne 0 ]
do
if (($a%4==0));
then
echo "its a leap year"
else
echo "not a leap year"
fi
break;
done

14. To find factorial of a number.

#!/bin/bash
echo "enter a number"
read a
fact=1
while [ $a -ge 1 ]
do
fact=`expr $fact \* $a`
a=`expr $a - 1`
done
echo "factorial is $fact"

15. To generate a multiplication table


#!/bin/bash
echo "enter a number"
read a
n=1
while [ $n -ne 11 ]
do
echo "$a * $n = "`expr $a \* $n`
n=`expr $n + 1`
done
Q14. ENVIRONMENT
VARIABLES AND LOCAL
VARIABLES

HOME,LANG,SHELL,USER,DISPLA
Y,VISUAL
Q 15. Concept of etc
dir. and special
permissions
/etc/passwd :-

/etc/shadow

Su :-
Suid :-

Sgid :-

Sticky bit :-
Q16. FILTER
COMMANDS
Aspell :-

Cut :-
Diff :-

Sort :-
Tail :-
Tr :-

Uniq :-
Wc :-

Q 17. Filter Commands


Grep :-
Sed :-

Awk :-
Q18.PRACTICLE
EXERCISE 5
1. Write a shell script to show following(Using Case construct)

a. show present working directory

b. show files in directory

2. write a shell script to create a menu driven over given


option.

a. Number of user logged into system

b. Print calendar of current year.


c. User name

3. To print the corresponding day using case control structure.


4. write 2a shell script to check whether the entered character
is in small case, capital case, digit or special symbol.
5. write a shell script to check whether the entered character
start with small case or capital case.

6. write a shell script to check whether the word start with


digit or alphabet.

7. Write a shell script to check whether the entered word is


one or two or three letter word.
8. Write a shell script to check whether the entered word
starts with small case vowel or capital vowel or ends with a
digit.

#!/bin/bash

echo "enter a string or file name"

read a

ch=`echo $a | cut -c 1`

len=`expr $a|wc -c`


length=`expr $len - 1`

dh=`expr $a|cut -c $length`

if [[ $ch = [aeiouAEIOU] ]];

then

case $ch in

[AEIOU]) echo "$a starts with upper-case vowel";;

[aeiou]) echo "$a starts with lower case vowel";;

esac

case $dh in

[0-9]) echo "$a ends with a digit"

esac

else

echo "$a starts with consonant"

case $dh in

[0-9]) echo "$a ends with a digit"

esac

fi

9. write a shell script to calculate simple interest for 3 sets of


principle, no. of year and rate of interest.
10. Write a shell script to find LCM and HCF of two
numbers.

11. Write a shell script to check whetherthe number


entered is prime or not.
#!/bin/bash
echo "enter a number"
read a
flag=0
for (( i=2; i <=a/2; i++ ))
do
r=`expr $a % $i`
if [ $r -eQ 0 ];
then
flag=1
break
fi
done
if [ $flag -eQ 0 ] ;
then
echo "prime number"

else
echo "not a prime number"
fi

12. Write a shell script to count even and odd digit of a


number.
#!/bin/bash
echo "enter a number"
read a
e=0
f=0
while [ $a -gt 0 ]
do
d=`expr $a % 10`
a=`expr $a / 10`
if(($d%2 == 0));
then
e=`expr $e + 1`

else
f=`expr $f + 1`

fi
done
echo "even count = $e"
echo "odd count = $f"

13. write a shell script to print prime number between 1


and 20.
14. write a shell script to check whether the given number
is Armstrong or not.
15. write a shell script to display number of vowels in a
string.
16. Write a shell script to count of files in a directory.
17. Write shell script to show various system configuration like
1) Currently logged user and his logname
2) Your current shell
3) Your home directory
4) Your operating system
5) Your current path setting
6) Your current working directory
7) Show Currently logged number of users
8) About your os and version ,release number , kernel version+
9) Show all available shells
10) Show mouse settings
11) Show computer cpu information like processor type, speed
etc
12) Show memory information
13) Show hard disk information like size of hard-disk, cache
memory, model etc
14) File system (Mounted)

Vous aimerez peut-être aussi