
Patrick B. answered 03/01/21
Math and computer tutor/teacher
$ cat command_menu
#! /bin/bash
# menu interface to simple commands
echo -e "\n" COMMAND MENU\n"
echo " a. Current date and time"
echo " b. Users currently logged in"
echo " c. Name of the working directory"
echo - e " d. Contents of the working directory\n"
echo -n "Enter a, b, c, or d: "
read answer
echo
###############################
# Problem #1
#---------------------------------
# copies the specified file into
# your KEEP directory and opens
# it up in VI
####################################
if test $# = 1 # IF the number of command line arguments is 1
then
if test -f $1 # IF the file is a regular file and not a system file
then
cp $1 $HOME/keep # moves the file to your KEEP folder
vi $1 # and opens it in VI
else
echo "file not found try again
fi
else
echo "You must specify a file name. Try again"
fi
###############################
# Problem #2
#---------------------------------
# checks every 30 seconds
# for the specified user
# to log on
####################################
# pipes the output of who is currently loggeed on
# to grep, which fileters for the username specified;
# if present, gets returned while the remaining output
# gets wasted;
until who | grep "$1" > /dev/null
do sleep 30 # sleeps/waits for 30 seconds
done
echo "$1 is logged on." exit 0 # bails once condition is
# met and loop stops
#Problem 3
case answer in
"a")
date
;;
"b")
who
;;
"c")
pwd
;;
"d")
ls
;;