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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New FAQ - Easily add menus to your shell script with this function 2

Status
Not open for further replies.

RobJordan

MIS
Apr 3, 2001
296
US
faq80-1606

Create shell menus in minutes or seconds...
note: text below may not align correctly
as it will on a terminal or telnet session.

This sample menu was created with two commands using the
Create_Menu function

ls >> $TMP_LIST.menu
Create_Menu $TMP_LIST.menu "" "Main Menu"

Main Menu
--------------------------------------------------------------------------------
1) PST 2) Validate 3) array.fun
4) check_script 5) check_script.bak 6) find_term
7) findit 8) findit.bak 9) findit.beta
10) index.html 11) lsit 12) menu.bak
13) menu.fun 14) menu.fun.bak 15) portman
16) portman.beta.091701 17) root 18) speed_test
19) test 20) test2 21) test_file
22) trapit.fun 23) tuxtool 24) tuxtool.010202
25) tuxtool.array.bak 26) tuxtool.bak.gz 27) update
28) validate.fun 29) yesterday.fun

Enter choice OR press [ENTER] to repeat menu
Enter x to exit
-->

Robert Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
Nice script. Here's an easy on using 'select' - just not quite as flexible.

This lets you pick a file in the current directory and obtain the file size - any processing could go here.

The * can be changed for any string `echo A B C` or variable
`echo commandlist` and then process whatever the choice.

#! /bin/sh
# Works in sh,bash,ksh
PS3="Show file size: " # Prompt string
select file in *
do
echo &quot;<$file> is `wc -l \&quot;${file}\&quot; | cut -d ' ' -f1`&quot;
break
done
# End of script

Cheers,
ND
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top