Text: (6 pts.) Follow these steps:
Copy Example8.sh (from the lecture video) into a new script named Exercise1.sh
Modify Exercise1.sh so that it takes the directory name as a command line argument instead of automatically using the current directory
Hint 1: This can be done by adding only three characters to Exercise1.sh
Hint 2: Leave the function examine_objects() alone.
When you test your script on a different directory, you'll see that it won't work:
The problem is that the script still looks in the current directory for these objects even though these objects are listed from a separate directory. We'll fix this in #2.
Example 8:
#!/bin/bash
function examine_object() {
if [ -e $1 ]; then # If the object represented by $1 exists
echo "Object $1 exists. Checking type."
if [ -f $1 ]; then # If the object represented by $1 is a file
echo "Object $1 is a file. Checking if it's empty."
if [ -s $1 ]; then # If the file represented by $1 is NOT empty
echo "Object $1 is not empty."
else # The file represented by $1 IS empty.
echo "Object $1 is empty."
fi
elif [ -d $1 ]; then # If the object represented by $1 is a directory
echo "Object $1 is a directory."
else # The object represented by $1 is neither a file nor a directory
echo "Object $1 is something else."
fi
else # The object represented by $1 does NOT exist
echo "Object $1 does not exist."
fi
echo
}
for f in `ls`; do
examine_object $f
done