Shell programming college questions
Shell programming college questions
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:
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.
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.
(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.