Enter the following script named savefiles, and give yourself execute permission to the file:

$ cat savefiles
#! /bin/bash
echo "Saving files in working directory to the file savethem."
exec > savethem
for i in *
do
echo
"==================================================="
echo "File: $i"
echo
"==================================================="
cat "$i"
done

a. Which error message do you receive when you execute this script?
Rewrite the script so that the error does not occur, making sure the output
still goes to savethem.
b. What might be a problem with running this script twice in the same
directory? Discuss a solution to this problem.

a. You receive the following error message:
cat: savethem: input file is output file
To eliminate the error message, add the following lines after the line with
do on it:
if [ $i == "savethem" ] ; then
continue
fi
b. Each time you run savefiles, it overwrites the savethem file with the cur-
rent contents of the working directory. When you remove a file and run

savefiles again, that file will no longer be in savethem. If you want to keep
an archive of files in the working directory, you need to save the files to
a new file each time you run savefiles. If you prefix the filename savethem
with $$, you will have a unique filename each time you run savefiles.

Computer Science & Information Technology

You might also like to view...

A(n) ________ is displayed before a video begins playing

A) poster frame B) introductory frame C) timing frame D) video frame

Computer Science & Information Technology

Which of the following communication devices needs to have a subscription to a service provider for Internet access?

A. Cellular WAN B. Infrared C. Bluetooth D. WLAN (802.11g)

Computer Science & Information Technology