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:

  1. Write a script named e1.bash that defines two functions: savedir and restoredir. The savedir function must save the current working directory somehow. The restoredir function must restore the current working directory to the directory when savedir was last called. This script is intended to be sourced into the environment and not executed.

  2. Write a script that prints the top ten most frequent commands with their frequencies from the output of the history bash builtin. If there are fewer than ten commands in the history, then print all the commands and frequencies.

  3. Write a script named e3.bash that 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 bash

  4. Write a script named e4.bash that creates a zip file of all files that have .txt file extension recursively from within the current working directory.

  5. Write a script named e5.bash that finds the most recently modified file recursively from the current directory.

Notes:

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

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"