Computing.Net > Forums > Unix > Unix Command Script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix Command Script

Reply to Message Icon

Name: Tom
Date: November 22, 2002 at 17:28:05 Pacific
OS: Unix
CPU/Ram: 4/512MB
Comment:

I'm new to unix and I'm writing a bash script that will prompt 5 command menu. I got stuck on the last two command that ask for the emalier with a subject & an attachment and the menu that's surrounded by a loop so that when one option is concluded it will go back to the menu until the user selects an option x to exit. Any help would be appreciated. Here is an example of the program I wrote so far but got stuck on number 4 and 5:

#!/bin/bash

echo -e "\n COMMAND MENU\n"
echo " 1. Current date and time"
echo " 2. Users currently logged in"
echo " 3. Name of the working directory"
echo " 4. Email someone with a subject and an attachment"
echo -e " 5. Press X to exit\n"
echo -e "Enter 1-5: \c"
read answer
echo
case "$answer" in
1.)
date
;;

2.)
who
;;

3.)
pwd
;;

4.)


5.)


*)
echo "There is no selection: $answer"
;;

esac

-----------------------
Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: November 22, 2002 at 18:51:24 Pacific
Reply:

#!/bin/ksh
# set -x
localmail() {
echo "What is the mail recipient?"
read mailto
echo "What full path to the file would you like to attach?"
read fullpath
attachment=`echo $fullpath | awk -F "/" '{ print $NF }'`
echo "What is the subject of the mail message?"
read subject
echo $mailto $fullpath $subject $attachment
(uuencode $fullpath $attachment; echo "text") | mail -s "$subject" $mailto
}
echo ""
echo "COMMAND MENU"
PS3='Your choice? '
select ans in \
"Current date and time" \
"Users currently logged in" \
"Name of the working directory" \
"Email someone with a subject and an attachment" \
"Exit"
do
case $REPLY in
1 ) date ;;
2 ) who ;;
3 ) pwd ;;
4 ) localmail ;;
5 ) exit 0 ;;
* ) echo "Sorry, no default selection" ;;
esac
done


0

Response Number 2
Name: Tom
Date: November 23, 2002 at 20:49:28 Pacific
Reply:

The script work perfect. Thanks for your help David.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix Command Script

Using a script with UNIX commands t www.computing.net/answers/unix/using-a-script-with-unix-commands-t/3781.html

Unix Command www.computing.net/answers/unix/unix-command/2209.html

unix command to open the xls file www.computing.net/answers/unix/unix-command-to-open-the-xls-file/6301.html