I have to modify this script, but leave the usage statement as it is.This is the
ID: 3768704 • Letter: I
Question
I have to modify this script, but leave the usage statement as it is.This is the script I have in Unix so far:
#template.sh - edit this file
function usage
{
echo "usage: $0 arguments ..."
if [ $# -eq 1 ]
then echo "ERROR: $1"
fi
}
if [ $# -eq 0 ]
then usage
else
echo MyName
date
echo
usage
for arg
do
echo "Error: Do not know what to do with $arg"
echo "*****"
done
fi
I have to modify it so that if there is an argument on the command line called TestError then I display this message along with my usage statement:
For Example:
If there is an argument on the command line called now then I display the current time as:
It is now HH:MM:SS [AP]M
For Example:
*Unix
Explanation / Answer
for arg in "$@"; do
case $arg in
TestError)
usage $*
;;
now)
time=$(date +%X)
echo "It is now $time"
;;
*?)
echo "My Name"
date
echo
usage
printf "%s ***** " "Do not know what to do with " "$@"
;;
*)
usage
;;
esac
done