Hello,
I'm working on a bash script for a linux class that I'm taking. It's a command menu that uses an until loop and the case command.
This is probably such a newbie problem but I've searched the internet far and wide and have found no solutions.
The problem I'm having is this:
The until loop needs to include the line where they select a letter because I need the user to select a letter each time it loops. But then how do reference the variable before I define the variable? I'm guessing it can't be done this way, but I can't think of any other test that would make sense for this loop. (the loop should keep going until the user enters "j" to exit.
When I run this, it displays the menu and then immediately exits the program. No error messages, I just get a new prompt.
I don't want someone to necessarily fix it because it's an assignment that I need to learn from, but any nudges in the right direction would be greatly appreciated!
Thanks!
Jill
I'm working on a bash script for a linux class that I'm taking. It's a command menu that uses an until loop and the case command.
This is probably such a newbie problem but I've searched the internet far and wide and have found no solutions.
The problem I'm having is this:
The until loop needs to include the line where they select a letter because I need the user to select a letter each time it loops. But then how do reference the variable before I define the variable? I'm guessing it can't be done this way, but I can't think of any other test that would make sense for this loop. (the loop should keep going until the user enters "j" to exit.
When I run this, it displays the menu and then immediately exits the program. No error messages, I just get a new prompt.
Code:
#!/bin/bash
echo -e "\n COMMAND MENU\n"
echo " a. Email Program"
echo " b. Users currently logged on"
echo " c. Current Date and Time"
echo " d. This month's Calendar"
echo " e. Name of the Working Directory"
echo " f. Contents of the Working directory"
echo " g. Find the IP of a Web Address"
echo " h. See Your Fortune"
echo " i. Print a File"
echo " j. Exit"
echo
until [ "$char"="j" ]
do
read "Please select a letter: " char
case "$char" in
a)
read "Enter the subject line: " subj
read "Enter the email address: " addr
mail -s "$subj" "$addr"
;;
b)
who
;;
c)
date
;;
d)
calendar
;;
e)
pwd
;;
f)
ls
;;
g)
read "Enter the web address" wadd
host "$wadd"
;;
h)
fortune
;;
i)
read "Enter the name of the file: " fnam
more "$fnam"
;;
j)
exit
;;
esac
done
I don't want someone to necessarily fix it because it's an assignment that I need to learn from, but any nudges in the right direction would be greatly appreciated!
Thanks!
Jill
Last edited by a moderator: