Shell Scripting
Due: 5:00am, Monday, February 10, 2025
Description
The purpose of this assignment is to get practice with shell scripting. Write the following scripts in bash:
Write a script named
e1.bashthat defines two functions:savedirandrestoredir. Thesavedirfunction must save the current working directory somehow. Therestoredirfunction must restore the current working directory to the directory whensavedirwas last called. This script is intended to be sourced into the environment and not executed.Write a script that prints the top ten most frequent commands with their frequencies from the output of the
historybash builtin. If there are fewer than ten commands in the history, then print all the commands and frequencies.Write a script named
e3.bashthat takes a program as a command line argument and runs the program until it fails and prints the standard out and standard error output of the failing run of the program. This can be useful for debugging purposes. The appendix has a bashWrite a script named
e4.bashthat creates a zip file of all files that have.txtfile extension recursively from within the current working directory.Write a script named
e5.bashthat finds the most recently modified file recursively from the current directory.
Notes:
Executable scripts must have a correct shebang line; the shebang must be the first line in the script.
The
pushdandpopdbash builtins are not allowed for this assignment.Here are some command line programs that might be useful:
cut,find,head,sort,tail,tr,uniq,xargs
Turning in the Assignment
To submit your assignment, create a zip file of a DIRECTORY named
project1 containing ONLY the e?.bash files. Then submit that file to
the appropriate folder on D2L.
Grading Criteria
Correct documentation
Correct implementation of the specification
No errors reported by
shellcheck.
Appendix
A bash script that randomly fails to test e2.bash:
#!/usr/bin/env bash
n=$(( RANDOM % 100 ))
if [[ n -eq 23 ]]; then
echo "FAILURE"
>&2 echo "ERROR"
exit 1
fi
echo "SUCCESS"