You are on page 1of 8

LAB CYCLE II

A) 1) Ramesh basic salary is input through the keyboard. His dearness allowance is 40% of basic salary and house rent allowance is 20% basic salary. Write a shell program to calculate his gross salary 2) The distance between two cities (in KM) is input through the keyboard .write a shell 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 through the keyboard. Write a shell program to calculate the area and perimeter of the rectangle, square and the area and circumference of the circle. 4) Write a shell script which deletes all lines containing the word UNIX, in the files supplied as arguments to this shell script.

5) Write a program to check how many users working on the system 6) While executing a shell script either the LOGNAME or the UID is supplied at the command prompt. Write a shell program to find out at how many terminals has this user logged in. 7) Write a shell program to find the number of ordinary files and Directory files in the Present directory. B) 1) Write a program to find largest number of two numbers 2) write a program to check given number is +ve or ve number 3) Write a shell program to check the given number is odd number or even number. 4)Write a program to check whether two strings are equal or not 5) If cost price of an item is input through the keyboard. Write a shell program to determine whether the seller has made profit or incurred loss

and also determine how much profit was made or loss incurred. 6)Write a shell program 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. 7) Write a shell script which receives two file names as arguments. It should check whether the two files contents are same or not. If they are same then second file should be deleted. (Hint: Use the CMP command to compare the files) C) 1) write a shell program to calaculate the sum of the digits of the given number

2) Write a program to find the factorial value of any number entered through the key board. 3) Two numbers are entered through the key board. Write a program to find the value of one number raised to the power of another.
4)

Write a program to print all prime numbers from 1 to 50

Using while loop 5) Write a program to generate all combinations of 1, 2 and 3 using for loop. 6) Write a program to calculate overtime pay of 10 employees and the overtime pay is at the rate of Rs 12.00 per hour for every hour worked above 40 hours. 7) Write a shell script which displays a list of all files in the current directory to which you have read, write and execute permissions. D) 1) Write a shell program to reverse the given string 2) Write a shell program to count the number of vowels in the given string

3) write a shell program to print the following pattern unix uni un

u 4) write a shell program to find file with the maximum size in the current directory and display file name and its size also 5) A shell script receives even number of file names .Suppose four file names supplied then the first file should get copied into second file, the second file should get copied into third file and soon. If odd number of file names supplied then no copying should take place and an error message be displayed. 6) Write a shell script which will receive any number of file names as arguments the shell script should check whether every argument supplied is a file or directory. If it is a directory it should be appropriately reported. If it is a file then name the file as well as number of lines present in it should be reported. 7) Write a shell script will receive any number of file names 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 does not exist then it should be created and in it the files supplied as arguments get created. If mydir already exists then it should reported along with the number of files that are currently present in mydir.

E) 1) Write a shell program for the following display menu 1. date 2. cal 3. pwd 4. tty 5. Exit

Using case control statement


2)

Write a shell program to display the message Good Morning or Good Afternoon or Good Evening depending on the system time Using case control instruction

3)

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( Using case control instruction) 4) A shell script can receive the following four options. OPTION MEANING -c -v -s -t cga mode vga mode single player two players

Write a shell program using getopts which should receive one or more of these options from the command prompt check their validity and display appropriate messages depending on the option selected. 5) 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 way. i)$mycd dir ii)$mycd #should cd into dir

#should cd into previous directory.

6) Write a function mkcd () which would create all the directories present in the path supplied to its argument and change over to the last directory in this path. Thus $mkcd d1/d2 /d3/d4/d5 should create the five nested directories and change the present working directory to d5.

You might also like