Assignment_2 (2)
Assignment_2 (2)
C: This assignment have two parts part-1 and part-2 ,first part consist of 12 different types question,
and part-2 consist of 13 different types questions out of which you have to do a minimum of 10
questions from each part ie a total of 20 questions for final submission.
D:Attempt problems related to one part at same place with appropriate sr.no.
F:Submit a pdf file consisting code of script followed by the output window of your terminal.
Part-I
4- Write a shell script that first displays the total number of arguments passed to it using $# and
checks if exactly 3 arguments were given, if not, it outputs an error
message and exits with a status code of 1, indicating an error,if 3
arguments are passed, the script prints each argument along with its
position.
5- Write a shell script to print a number in reverse order which should support the following
requirements:
a. The script should accept the input from the command line.
b. If we don’t input any data, then it displays an error message to execute the script correctly.
6-write a shell script to find the unique words in a file and also count the occurrence of each of these
words.
7- Write a shell script to perform the following user operations:
a. Print sorted list of users
c. Search for any specific user and display no. of times the user logged in
d. Check if any specific user is terminally active e. List all users without password.
(Hint: Use Pipes to achieve the result)
8-Write a shell script to declare an array, (with at least 5 elements), assign values to it, and access its
elements which is having underwritten functionality (array elements can be strings, numbers, or a mix
of both)
c. Uses loop to iterate through all the elements of the array and print each element with its
corresponding index.
9-write a shell script using function, declare at least three functions in the script which perform
following task
b. A function that takes two numbers as arguments, calculates their sum, and returns or prints the
result.
10-Write a shell script to read a directory name and delete all zero-sized file from it and its sub-
directories.
11-Write a shell script to compare identically named files in two different directories and if they are
the same, copy one of them in a third directory.
12-Write a shell script to display all files in any specific directory (read from the user) in the following
format:
Also, display the total number of files and total space occupied by directory.
Part-II
1-Write a shell script that determines if a specific word exists in a given line of a file the script will
search for the word in each line of the file and indicate whether the word was found,script checks if
exactly two arguments are provided, filename and the word to search for, if not, it prints a usage
message and exits.
2-Write a shell script to read the name (or path) of 2 directories and copy all the files from them into
a new directory.
3-write a shell script that determines the operating system (OS) of the machine it is running. (use pipe
and switch case only)
4-Write a shell script and use for loop to move all the files in the current directory to another specified
directory.
5-Write a shell script to display the date, time and greeting message (like Good Morning User etc.) The
time should be displayed with “AM” or “PM” and not in terms of 24-hour notation.
6- Write a shell script that prompts the user to enter three numbers. use nested if-else statements to
compare the three numbers and determine:
7-Write a shell script to read the name of a directory and display the name of all executable files in the
given directory. Also, display the total count in the end.
8-Write a shell script to check if directory exists and if it exists, display list of files and directories (along
with subdirectories) in it.
9-Write a shell script to validate password strength, consider some assumptions for the password
string as given below.
If the password doesn’t comply with any of the above conditions, then the script should report it as a
<Weak Password>.
10-Create a shell script that uses the select loop to present a menu of options to the user. The script
should handle user input in dignified way, perform actions based on the selected option, and allow the
user to exit the script when desired.
2. Prompt Message: Use a user-friendly prompt message for the menu options. For example,
"Please select an option (1-4): ".
11-Create a shell script that demonstrates various forms of input and output redirection, script should
perform several tasks, using redirection to manage file input and output.
1. Create a File: Create a file named out.txt and write some initial content to it.
2. Append to File: Append additional content to out.txt based on user input.
3. Read from File: Read and display the contents of out.txt.
12-Create a shell script that takes input from command-line arguments to perform various tasks, it
should handle different types of input, validate them, and use them to execute specific commands or
operations.
Functionality of script:
o Display Help: If the user provides --help or -h as an argument, display a help message
that describes the script's usage.
o Display Current Date: If the user provides --date or -d, display the current date and
time.
o List Files: If the user provides --list or -l followed by a directory path, list the files in
the specified directory.
o Count Lines in a File: If the user provides --count or -c followed by a file path, count
the number of lines in the specified file.
o Error Handling: Handle cases where required arguments are missing or invalid
13- Write a shell script which reads a text file and output the following: