Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a menu in Unix shell

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
How do a create a Unix shell menu that will display all the questions and allow users to tab thru (as in smitty) ?<br>eg<br>___________________________<br>User Main Menu<br>==============<br>Enter User Name [&nbsp;&nbsp;&nbsp;&nbsp;] <br>Enter User Group [&nbsp;&nbsp;&nbsp;]<br>Enter User Role&nbsp;&nbsp;[&nbsp;&nbsp;&nbsp;]<br><br>Press ENTER after all input<br>---------------------------<br>
 
i wrote this program u can use it they way you like.<br>this is my menu which it calls in the program called menu1.txt.<br>#####################################################################<br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# <br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VWSA CAD/CAM OPERATORS BACKUP MENU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4.&nbsp;&nbsp;EXIT<br><br>this is the actual program .<br>!/bin/ksh<br>#=========================================================<br>#author : R.Baderoon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#<br>#description : interactive program to check backup&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#<br>#=========================================================<br>icontinue()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;\nReturn to Menu Y/N : \c &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read ANSWER<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if [ &quot;$ANSWER&quot; = &quot;N&quot; -o &quot;$ANSWER&quot; = &quot;n&quot; ]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if [ &quot;$ANSWER&quot; = &quot;Y&quot; -o &quot;$ANSWER&quot; = &quot;y&quot; -o &quot;$ANSWER&quot; = &quot; &quot; ]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear ; cat menu1.txt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;SELECT OPTION AND ENTER : \c&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi<br>&nbsp;&nbsp;&nbsp;&nbsp;fi<br>}<br><br>set -o ignoreeof<br>trap ' ' 1 2 3 15<br>PWD=/vw/addback/logs<br>clear; cat menu1.txt <br>echo&nbsp;&nbsp;&quot;SELECT OPTION AND ENTER : \c&quot;<br><br>while [ &quot;$menu&quot; != &quot;4&quot; ]; do&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;read menu<br>&nbsp;&nbsp;if&nbsp;&nbsp;[ &quot;$menu&quot; = &quot;1&quot; ]<br>&nbsp;&nbsp;&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Busy ! &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ls -lart $PWD ¦ tail<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;icontinue <br>&nbsp;&nbsp;&nbsp;&nbsp;if trap ' ' 0 1 2 3 15 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear;cat menu1.txt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&nbsp;&quot;SELECT OPTION AND ENTER : \c&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;fi <br>&nbsp;&nbsp;fi<br><br>&nbsp;if [ &quot;$menu&quot; = &quot;2&quot; ]<br>&nbsp;&nbsp;&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if test -f &quot;/vw/addback/backup_busy&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Backup busy ,cannot unload tape &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep 5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Unloading tape,Please wait !&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tctl -f /dev/rmt0.1 rewoffl<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if trap ' ' 0 1 2 3 15<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear;cat menu1.txt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&nbsp;&quot;SELECT OPTION AND ENTER : \c&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi <br>&nbsp;fi<br><br>&nbsp;if [ &quot;$menu&quot; = &quot;3&quot; ]<br>&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;clear;cat $PWD/last_scheduled_backup ¦ read last_tape <br>&nbsp;&nbsp;&nbsp;banner tape-$last_tape<br>&nbsp;&nbsp;&nbsp;&nbsp;icontinue<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if trap ' ' 0 1 2 3 15<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear;cat menu1.txt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&nbsp;&quot;SELECT OPTION AND ENTER : \c&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi<br>&nbsp;fi<br><br>&nbsp;if [ &quot;$menu&quot; = &quot;4&quot; ]<br>&nbsp;&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;\nYOU ARE NOW LOGGING OFF!\n &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;sleep 3<br>&nbsp;&nbsp;&nbsp;&nbsp;exit<br>&nbsp;fi <br>done<br>
 
I think the following may help - it makes use of the tput command to position a cursor. After each entry you will need to press <ENTER> rather than <TAB> but it does the same thing.

---------------- START OF SCRIPT -----------------
#!/usr/bin/ksh

# File: menuDisplay
# Purpose: display a menu and allow user input after.

tput clear

tput cup 10 5
echo &quot;USER MAIN MENU&quot;
tput cup 11 5
echo &quot;==============&quot;
tput cup 15 10
echo &quot;Enter userid: &quot;
tput cup 17 10
echo &quot;Enter Group: &quot;
tput cup 19 10
echo &quot;Enter Role: &quot;

# Get user entry
tput cup 15 24; read usernm
tput cup 17 24; read usergp
tput cup 19 24; read userrl

# display values.
tput cup 21 5
echo &quot;Username: $usernm Group: $usergp Role: $userrl\n&quot;
 
Has anyone of you heard about the [tt]select[/tt] built-in command?
I hope it works...
Unix was made by and for smart people.
 
If u want to use smit with specific comands, u can customize smit menus and define how smit interacts with ODM.

Best Regards
Igor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top