Você está na página 1de 4

MCA 4th Semester

ASSIGNMENT: UNIX/LINUX SHELL PROGRAMMING

1. Rameshs basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house
rent allowance is 20% of basic salary. Write a shell script program to calculate his gross salary.
2. The distance between two cities (in km.) is input through the keyboard. Write a a shell script program to convert
and print this distance in meters, feet, inches and centimeters.
3. The length and breadth of a rectangle and radius of a circle are input though the keyboard. Write a shell script
program to calculate the area and perimeter of the rectangle and the area & circumference of the circle.
4. If a five digit number is input through the keyboard, write a shell script program to calculate the sum of its
digits. (Hint: use the modulus operator %)
5. The file /etc/passwd contains information about all the users. However it is difficult to decipher the information
stored in it. Write a shell script which would receive the logname during execution, obtain information about it
from /etc/passwd and display this information on the screen in easily understandable format. (Hint: Use cut
command)
6. Write a shell script which will receive either the filename or the filename with its full path during execution.
This script should obtain information about this file as given by ls l and display it in proper format.
7. In a company, an employee is paid as under:
If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic. If his salary is
either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic salary. If the employees salary
is input through the keyboard write a program to find his gross salary.
8. The marks obtained by a student in 5 different subjects are input through the keyboard. The student gets a
division as per the following rules:
Percentage above or equal to 60 First Division
Percentage between 50 and 59 Second Division
Percentage between 40 and 49 Third Division
Percentage less than 40 Fail
Write a shell script program to calculate the division obtained by the student.
9. If cost price and selling price of an item is input through the keyboard, write a shell script program to determine
whether the seller has made profit or incurred loss. Also determine how much profit was made or loss incurred.
10. Any integer is input through the keyboard. Write a shell script program to find out whether it is an odd number
or even number.
11. Write a shell script which receives any year from the keyboard and determines whether the year is a leap year or
not. If no argument is supplied the current year should be assumed.
12. Write a shell script which receives two filenames as arguments. It should check whether the two files contents
are same or not. If they are same the second file should be deleted. (Hint: Use the cmp command to compare
files)
13. Write a shell script which will automatically get executed on logging in. This shell script should display the
present working directory and report whether your friend whose logname is aa10 has currently logged in or not.
If he has logged in then the shell script should send a message to his terminal suggesting a dinner tonight. If you
do not have a write-permission to his terminal or if he hasnt logged in then such a message should be mailed to
him with a request to send confirmation about your dinner proposal.
14. While executing a shell script either the LOGNAME or the UID is supplied at the command prompt. Write a
shell script to find out at how many terminals has this user logged in.
15. A shell script can receive an argument one, two, or three. If the argument supplied is one display it in
bold, if it is two display it in reverse video and if it is three make it blink on the screen. If a wrong argument
is supplied report it. (Hint: Use an elif statement)
16. Any year is entered through the keyboard, write a shell script program to determine whether the year is leap or
not. (Hint: Use the logical operators a and o).
17. Write a shell script which gets executed the moment the user logs in. It should display the message Good
Morning / Good Afternoon / Good Evening depending upon the time at which the user logs in.
18. Write a menu driven program which has the following options:
i) Contents of /etc/passwd.
ii) List of users who have currently logged in.
iii) Present working directory
iv) Exit.
Make use of case statement. The menu should be placed approximately in the centre of the screen and should be
displayed in bold using the tput statement.
19. Write a shell script program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs. 12.00
per hour for every hour worked above 40 hours. Assume that the employees do not work for fractional part of an
hour.
20. Write a program to find the factorial value of any number entered through the keyboard.
21. Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the
power of another.
22. Write a shell script which reports names and sizes of all files in a directory (directory would be supplied as an
argument to the shell script) whose size is exceeding 100 bytes. The filenames should be printed descending
order of their sizes. The total number of such files should also be reported.
23. A friend of yours has promised to log in at a particular time. However, he has not kept the promise. You want to
contact him a soon as he logs in. Write a shell script which checks after every one minute whether your friend
has logged in or not. The logname should be supplied to the shell script at command prompt. (Hint: Use until
loop).
24. Write a shell script program to count and report the number of entries present in each sub-directory mentioned in
the path which is supplied as command line argument.
25. Write a shell script program to print all prime numbers from 1 to 500. (Hint: Use nested loops, break and
continue).
26. Write a shell script program to generate all combinations of 1, 2 and 3 using for loops.
27. Write a shell script for renaming each file in the directory such that it will have the current shell PID as an
extension. The shell script should ensure that the directories do not get renamed.
28. A file called wordfile consists of several words. Write a shell script which will receive a list of filenames, the
first of which would be wordfile. The shell script should report all occurrences of each word in wordfile in the
rest of the files supplied as arguments.
29. Write a shell script which deletes all lines containing the word unix in the files supplied as arguments to this
shell script.
30. The word unix is present in only some of the files supplied as arguments to the shell script. Your shell script
should search each of these files in turn and stop at the first file that it encounters containing the word unix. This
filename should be displayed on the screen.
31. A shell script receives even number of filenames. Suppose four filenames are supplied then the first file should
get copied into second file, the third file should get copied into fourth file, and so on. If odd number of filenames
are supplied then no copying should take place and an error message should be displayed.
32. Write a shell script which displays a list of all files in the current directory to which you have read, write and
executer permission.
33. Write a shell script which will receive any number of filenames as arguments. The shell script should check
whether every argument supplied is a file or a directory. If it is a directory it should be approximately reported.
If it is a filename then name of the file as well as number of lines present in it should be reported.
34. Write a shell script which will receive any number of filenames as arguments. The shell script should check
whether such files already exist. If they do, then it should be reported. If these files do not exist then check if a
sub-directory called mydir exists in the current directory. If it doesnt exist then it should be created and in it the
files supplied as arguments should get created. If mydir already exists then it should be reported along with the
number of files that are currently presently in mydir.
35. Suppose a user has renamed some files in current directory using a command like mv filename.$$.
Write a shell script to search all such files and rename them such that they do not contain the shell PID.
36. Write a shell script to identify all zero byte files in the current directory and delete them. Before proceeding with
deletion the shell script should get a conformation from the user. Note that for deletion r m -i should not be
used since it needs an Enter Key to be hit after supplying y or n.
37. Write a shell script which would display a message Terminal Locked on the screen and wait for the user to hit
a key. On receiving a key it should accept a password and then unlock the terminal if the password matches.
38. A shell script can receive one or more out of the following for options:
Option Meaning
-c CGA mode
-s Single player
-v VGA mode
-t Two players
Write a shell script using getopts which would receive one or more these options from the command prompt,
check their validity and display appropriate message depending on the option selected.
39. Write a shell script using getopts which can receive two options a and p. The option a is either followed by
an argument CGA or VGA, whereas the p option is followed by an argument SINGEL or TWO. Your script
should report which option have been used by the user as well as their validity.
40. Write a shell script which works similar to the wc command, this script can receive the options l, w, and c to
indicate whether number of lines, number of words or number of characters from the input stream are to be
counted. The user may use any or all of these options. Your script should be intelligent to identify invalid option
and reject them.
41. Write a shell script containing a function mycd( ) using which you would be able to shuttle between directories.
The function should work in the following manner:
$mycd dir # should cd into dir
$mycd - # should cd into previous directory

Você também pode gostar