Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . For each problem, submit 1 ) your program and 2 ) screenshots ( jpg or png format ) of the execution ( command

1. For each problem, submit 1) your program and 2) screenshots (jpg or png format) of the execution (command line and output) of the program. Check homework policies in the syllabus for details.
2. Include appropriate comments in your code to describe the functionality of different sections. This helps the grader understand and determine the correctness of your code.
3. Name your scripts and screenshots clearly, so that the grader knows which files are for which problem. For example, for problem 1, you may name the files as script_1.sh and screenshot_1.jpg (or screenshot_1_1.jpg and screenshot_1_2.jpg if you submit two screenshots).
4. Submit individual files. DO NOT SUBMIT A ZIP FILE.
5. The final submission must be your individual work. Copying or reengineering/paraphrasing code that was not developed by you is strictly prohibited. The use of AI-based code generators is prohibited.
Problem 1:
Write a Bash script that performs the following steps:
1. Prompts the user for a pathname of a directory, verifies the directory exists, and moves into that directory.
2. Lists all the files in the directory and displays a menu to the user to select a file.
3. After a file is selected, display the last ten lines of the file and ask the user if they want to display more. If the user responds "yes", display the next ten lines.
Continue displaying the next ten lines at a time as long as the user responds "yes". Stop "scrolling up" if the displaying reaches the first line of the file.
Problem 2:
Write a Bash script, which prints out the entries (including files and sub-directories) in a directory in a reversed order as what obtained using filename expansion. The pathname of the directory is provided as an argument. Assuming that with filename expansion you see /my/dir contains "cache cron games lib log run tmp," your program "reverse.sh /my/dir" will print "tmp run log lib games cron cache." You can print the names on one line, or each name on a line.
Use filename expansion, array, and at least one function reverse(). Your script should be able to correctly handle the entries with spaces in their names. For example, if a file is named "bash scripting.ppt", make sure that your script does not break the name into two parts: "bash" and "scripting.ppt".
DO NOT use the built-in command "sort -r" or "ls -r".
Problem 3:
Write a Bash script, which sorts a list of command line parameters in ascending order. For example, your command will look something like:
$ insert-sort.sh 7239-1
and type enter.
Your program will return: -12379
Use only basic commands and array. Do not use any built-in commands that sort array.
Problem 4:
Write a Bash script, which builds a table of counters for the files under /bin based on the first character in their filenames. For example, if there are no files with filenames starting with "a",23 files with their names starting with "b",..., and 10 files with their names starting with "z", the script would print
a 0
b 23
...
...
...
z 10
Use a loop to iterate through "a"-"z". Use an associative array to contain the counts. Print out the characters and the counts at the end of the script.
Note that your script must report the real numbers for the file names starting with lower case letters from 'a' to 'z'. There are no requirements on reporting numbers for other characters (symbols, such as "[", digits, or upper case letters).
Problem 5:
Write a Bash script that traverses a directory (provided as a command-line argument) and finds all duplicate filenames (files having the same name, not necessarily the same directory or contents). File name extension is considered as a part of filename.
Every time when the script finds a filename, which is a duplicate of another filename, the script should print out the pathnames of the duplicate files (both files), ask the user if they want to remove the newly found file, and delete the file if the user confirms the deletion.
You may use basename to strip directories and get only filenames from pathnames.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago

Question

explain what is meant by redundancy

Answered: 1 week ago