Creating a menu within a script file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a menu within a script file
# 1  
Old 12-09-2007
Creating a menu within a script file

I am very new to Unix and know the basic commands. I have to write a script file and I'm completely lost. The script file is to show the following at the beginning:

Menu of Options

1. Display all files in a user's home directory.
2. Welcome yourself to the program.
3. Display System Information
4. Exit back to Windows

I have been able to get this to display by use of the echo command. Beyond that, I have no idea what to do. I have search endlessly online for a way to create a menu in Unix and this is all I have to show for it. I also need a line that says "Please enter your choice." Once the user enters a choice, I have no idea how to write the various commands to perform what needs to be done.

Options 3 and 4 seem straightforward if I could get started. However, in option 1 the following criteria have to be met:

1. Display all files in a user's home directory. This should allow the user to look at any user's home directory, provided they enter the correct user name.
2. Put in a safeguard that if the user does not enter a name, that the current user's home directories display.

I have no idea how to work with Option 2.

I'd greatly appreciate it if anyone would please help me with this. Thank you.
# 2  
Old 12-09-2007
have a look at this






#!/bin/ksh
print "Select a terminal type"
cat << ENDINPUT
sun
ansi
wyse50
ENDINPUT
print -n "Which would you prefer? "
read termchoice

# this kind of code will let you display a menu and get input.
# and then use a case statmet to do each menu item selected.

case $termchoice
sun)
print "do stuff for a sun terminal"
;;
ansi)
print "do other stuff for a ansi terminal"
;;
wyse50)
print "do stuff for a wyse terminal"
;;
*)
print "Invalid option, Please try again. Use ’1’-’3’"
;;
esac

Last edited by robsonde; 12-09-2007 at 11:51 PM..
# 3  
Old 12-09-2007
Confused

Robs,

Thank you for the reply, but I'm still confused after reading it. For example, I have no idea what the "cat << ENDINPUT" means. What do "sun," "ansi," and "wyse50" have to do with anything? It would be much easier if you could use the information I provided to include with your response.

I can kinda figure out that "termchoice" relates to the selection that the user makes from the menu. However, you then have "sun", ansi, and wyse50 followed by a single parentheses on the following line. I don't get that at all either. Please provide an example that has to do with the information I gave. I could understand that much better. Thank you.
# 4  
Old 12-09-2007
The example he's given is just that - an example. Start by adapting that to get you close to what you need then we can help make the changes to get it just right.
Code:
cat << ENDINPUT
sun
ansi
wyse50
ENDINPUT

Just means to output to the screen everything up until 'ENDINPUT'. It's just an easier way to print multiple lines.
the ';;' within each case tells the script to stop checking the rest of the case options once it gets a match.

Last edited by Smiling Dragon; 12-10-2007 at 12:01 AM.. Reason: Explanation of ;;
# 5  
Old 12-10-2007
#!/bin/ksh
while true
do
print "What do you need to do today?"

cat << ENDINPUT # this is the start of a "here document"
1. Display all files in a user's home directory.
2. Welcome yourself to the program.
3. Display System Information
4. Exit back to Windows
ENDINPUT # this marks the end of the "here document"

print -n "Please enter your choice."
read option

case $option # this is a case statment , much like many if/then statments
1)
print "here we do all the code for option 1"
;;
2)
print "here we do all the code for option 2"
;;
3)
print "here we do all the code for option 3"
;;
4)
print "here we do all the code for option 4"
exit 0 # this will exit back to the shell
;;

*) # this line will catch anything other than 1-4 options.
print "Invalid option, Please try again. Use ’1’-’4’"
;;
esac # this ugly bit is the end marker of the case statment.
done







for more infomation on the "here document" stuff have a read on google.
BTW this code is untested and so probly has bugs :-)
# 6  
Old 12-10-2007
Okay...

Robs,

Thanks again. I'm now able to get the menu to display and I'm starting to slowly understand what you're posting. However, after the second "endinput", I have print -n "Please make a choice:" The problem is that when I run the program it says this:

print: Command not found.

I'd appreciate your help with this.
# 7  
Old 12-10-2007
Quote:
Originally Posted by sinjin
print: Command not found.

I'd appreciate your help with this.


try echo insted of print.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating bash script to process a data file based on the menu

Hey, im fairly new to unix and Im trying to make this unix project that would display a menu and do the following. MENU =========================== (p, P) Print users info (a, A) Add new user (s, S) Search user (d, D) Delete user (x,X) Exit Enter your choice: Trying to... (3 Replies)
Discussion started by: ultimaxtrd
3 Replies

2. Shell Programming and Scripting

Need help creating a menu.

Hi Master of masters, Thanks for ur reply. Need ur help for following. Is it possible to create menu for following in linux or a function. > Look in logs > Status > Action > End Action > CONFSUCCESS > Success > Show message as successful > Enter to continue > CONFFAIL > Failure > Show... (1 Reply)
Discussion started by: rajeshwebspere
1 Replies

3. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

4. Shell Programming and Scripting

Execution Problem with dispalying file content using menu driven script

HI All.. below is my menu options script. in option 2,3 and 4 im giving input and they are saving into their respective text file. problem is when im trying to "cat" those files in options 7,8 and 9 im not getting the output. no respective file contents are displaying on screen. but if i... (1 Reply)
Discussion started by: saichand1985
1 Replies

5. Shell Programming and Scripting

File Select Menu Script

Hi All, I need to develop a bash script list “list of files” and able to select if any and set as globe variable in script and use for other function. I would like to see in menu format. Example out put Below are the listed files for database clone 1. Sys.txt 2. abc.txt 3. Ddd.txt... (1 Reply)
Discussion started by: ashanabey
1 Replies

6. Shell Programming and Scripting

Menu in Menu script issue

Problem: I am trying to create a menu in a menu script and I am running into an issue with the calculator portion of the script. I am first presented with the ==Options Menu== which all 5 options working correctly. Now comes the fun part. I select option 1 which takes me to my ==Calculator... (1 Reply)
Discussion started by: iDdraig
1 Replies

7. Shell Programming and Scripting

Creating a menu

Hi, I need your help co create a very small menu somthing that look like this: 1. first step 2. second step 3. last step from step : ___ to step : ___ If the user choose 1 --> it will echo : Hellow If the user choose 2 --> it will echo : World If the user choose 3 --> it will echo... (4 Replies)
Discussion started by: yoavbe
4 Replies

8. Shell Programming and Scripting

Creating a menu from find

Hi I am wanting to create a menu that will list all the log files in a specific directory such as /apps/logs. So it would be something like this: #!/bin/ksh print 'Select The Required Log File' PS3='log? ' select choice in <this is to contain a list of files that are in a directory that... (3 Replies)
Discussion started by: markrj
3 Replies

9. Shell Programming and Scripting

Creating menu list from configuration file

Hi folks, I have the following function ,which generates menu for installation type: select_install_type() { echo echo ======================================== echo Please select the type of installation: echo ======================================== ... (8 Replies)
Discussion started by: nir_s
8 Replies

10. Shell Programming and Scripting

creating a menu for recycling and permanently deleting files.

Trying to alias rm to move files to a hidden trash directory in the bash shell. I've tried to create this alias numberous ways and it's just not working. Here's what I've tried, anyone have any suggestions. alias rm='mv $* ~/.trash' alias rm= 'mv$* ~/.trash' things like that... I've also... (2 Replies)
Discussion started by: strmy_ngts
2 Replies
Login or Register to Ask a Question