Creating menus in script file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Creating menus in script file
# 1  
Old 12-10-2007
Data Creating menus in script file

I'm very new to Unix and know the simplest of its commands. I am trying to write a script file that has a menu with the following options showing:

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

I am able to get the script file to at least show this when it is run. And I have a prompt that asks the user to make a selection. After that, I'm completely lost.

Option 1 is supposed to display all files in a user's home directory. It should allow a user to look up any user's home directory, provided they enter the correct user name. I have to put in a safeguard that if the user does not enter a name then their home directory is displayed.

Option 2 will ask a user to enter his or her name and will produce a welcome message with the user's name.

Here is the code that I have so far:


#! /bin/csh
# This is the UNIX menu script file that is for the second part of the
# take-home final.

cat <<ENDINPUT

CISS 125
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

ENDINPUT
echo Please enter your choice:
read option

case $option
1.

I'm completely lost and would appreciate any help that can be offered. Thank you.
# 2  
Old 12-10-2007
Quote:
Originally Posted by sinjin
4) Exit to Windows
What does this do?

This format of a case statement is

Code:
case "$variable" in
option1 )
          do-something
          ;;
option2 )
          do-something-else
          ;;
* )
          catch-all-case
          ;;
esac

# 3  
Old 12-10-2007
Porter, thanks for the info. However, I don't understand how when a person presses "1", "2", etc. that it will execute the proper command. In your post, does "option1" refer to the person pressing "1" for the menu?
# 4  
Old 12-10-2007
the "labels" are regular expressions that will match with the variable.

Code:
read option
case "$option" in
1 )
     ls -l
     ;;
2 ) 
     echo Welcome
     ;;
3 )
     uname -a
     ;;
4 )
     exit
     ;;
* )
     echo "Use 1, 2, 3 or 4"
     ;;
esac

# 5  
Old 12-10-2007
Porter,

I'm starting to understand this a little better. In option 1, I, or whoever is using the program, has to enter a user's name and have their home directory displayed. If no user name is entered, then the home directory of the person using the program is to be displayed. How would that be coded?
# 6  
Old 12-10-2007
Quote:
Originally Posted by sinjin
If no user name is entered, then the home directory of the person using the program is to be displayed. How would that be coded?
You know how to read a variable from the prompt so that gives you the username.

The tricky part is converting a username to a home directory.

Assuming OTHER is the name of the user...

Code:
eval OTHERHOME=`echo ~$OTHER`

I'm sure you can handle the directory listing.
# 7  
Old 12-11-2007
!/bin/ksh
#simlpmenu, A very simple menu

# amenu() defines a function to display a simple menu
amenu () {
# clear the screen
clear
echo `date`
echo
echo "\t\t\tSystem Administrator Menu"
echo
echo "\t\tPlease Select:"
echo
echo "\t\t\t 1. Ping Clients"
echo "\t\t\t 2. Reboot Clients"
echo "\t\t\t 3. Shutdown Clients"
echo "\t\t\t 4. Collect System Information"
echo "\t\t\t"
echo "\t\t\t 0. Exit"
echo Select by pressing a number and then ENTER ;
}

this is what i use
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating "menus" for script

I have a script I'm working on. I needed to figure out a way to display the following information for our Linux servers: What application runs on the server (app), who owns the application (owner) and the hostname. This is done by looking at a text file "test_owner_list" that has info like... (2 Replies)
Discussion started by: lombardi4851
2 Replies

2. Solaris

Workspace Manager Menus - dtwmrc file

When I execute this command: exec xterm –e $SHELL –c “sed –n 4p /folder1/folder2/folder3/file.dat; $SHELL” I have the expecting result: It opens an new terminal, it shows the 4th line of the file and the terminal window stays open  perfect. So I tried to write it in the dtwmrc file to have an... (1 Reply)
Discussion started by: damientdm
1 Replies

3. Shell Programming and Scripting

Need help in creating file restoration script from a backup script.

Hi all i am struggling in creating a restore of env files while doing applications clone. the first file i created for copying the important configurations file which is running perfect now for reverting the changes i mean when i am restoring these files to its original places i have to do... (7 Replies)
Discussion started by: javeedkaleem
7 Replies

4. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

5. UNIX for Dummies Questions & Answers

UNIX script for reading a file and creating another file

Hi, I am a beginner in scripting...I have to do a script where I have to read a file which has list of job names, line by line and for every line execute a dsjob command to find the log details of the job and extract only the start time of the job, if it is greater than jan 01 2008 and create... (1 Reply)
Discussion started by: Vijay81
1 Replies

6. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

7. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

8. UNIX for Dummies Questions & Answers

Script file menus and coding

I am very new to Unix and don't know much about it. I've been trying to create a menu and what I don't understand is how to execute a command once a user makes a selection. I have the menu set up. In fact, the following is the code that I have thus far: #! /bin/csh # This is the UNIX menu... (0 Replies)
Discussion started by: sinjin
0 Replies

9. Shell Programming and Scripting

Shell Script Menus - Rejecting invalid input (KSH)

Greetings all, I'm currently writing a shell script menu which is dynamically populated from an array. Have a question to ask about the filtering of invalid input. I'm using KSH. A brief description of my algorithm is as follows: 1) Read in input from user and store in a variable. (a valid... (2 Replies)
Discussion started by: rockysfr
2 Replies

10. Shell Programming and Scripting

Creating a file inside a script

Hi, How can I create a file inside a script. The thing is that, I have to create the file inside the script and it will be acting as a log file the script.Whenever I execute the script the file has to be created and the output has to be directed into that file. Tahnks in advance (11 Replies)
Discussion started by: sendhilmani
11 Replies
Login or Register to Ask a Question