0% found this document useful (0 votes)
6 views

Shell programming college questions

Uploaded by

xavierdaniel1202
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Shell programming college questions

Uploaded by

xavierdaniel1202
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

UNIX and Shell Programming

Assignment 8 : Shell Scripting

1. Print the values of the environment variables HOME, USER, SHELL and PATH
with set, print env and echo.

2. Store the output of the command “hostname” in a variable. Display “This script is
running on _.” where “_” is the output of the “hostname” command.

3. Write a script to take a single number from the user and perform the following
operations:

• Square of the number


• Cube of the number.
• Square root of the number.
• Logarithm (base 10) of the number.

4. Temperature of a city in Fahrenheit degree is input through the keyboard. Write a


program to convert this temperature into Centigrade degrees.
Formula is
c = (f - 32)*5 /9
f=9/5*c+32

5. Write a shell script that displays “man”,”bear”,”pig”,”dog”,”cat”,and “sheep” on the


screen with each appearing on a separate line. Use special characters to display the
filename, no of parameters, display the arguments each on one line, use appropriate
command to display the differences between $@, $*. Explain how about the status
code of the script.

6. Write a shell script to declare an array with fruits as elements. Print the following.
a. Print the elements at first and last index.
b. Print all elements in the array.
c. Number of elements in the array.

7. Write a shell script to create array of elements using command line argument as input
file. Check for the existence of the file. If the file exists, read the content and display the
frequency of occurrence of each word in the file.

8.Write a shell script to perform the following tasks:

1. Display the current date and time in a readable format.


2. Extract the month from the current date and store it in a file named date.txt.
3. Create an alias function to extract the day of the week from the current date.
4. Use the alias to execute the command and display the day of the week.

9. Use case statements and develop a bash script to perform the following action on a file.

Case 1: pass file name as an argument and write the even numbered line to a file
named evenfile.txt and odd numbered lines to oddfile.txt. Appropriate error messages
are produced if the argument is not a file.

Case 2: Print the number of lines and characters in the evenfile.txt, if exists

Case 3: Print the number of lines and characters in the oddfile.txt, if exists

Case 4: Read the contents of evenfile.txt and store it in an array. Display the contents
of the file by accessing the array.

10. Write a script that prints essentially the same information as ls -l a but in a more user-
friendly way.

(a) file exists or not

(b) regular file

(c) directory

(d) readable

(e) writable

(f) executable

(g) owner

Print suitable messages. Rewrite the above script as a shell function info and call the
function with a filename.

11. Write a program to generate all combinations of digits 1, 2 and 3 to form different
numbers using for loops

12. Write a menu-based program to copy a given file, to remove the specified file and to
move a file.

You might also like