- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Writing a Menu-Driven Script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 12:26 PM
тАО05-15-2007 12:26 PM
Writing a Menu-Driven Script
Can someone tell me how to get a menu driven script to execute a simple command? For example:
echo "\n >>> Enter for the current time"
read choice
case ${choice} in
If the user selects , how would you write this in the script to execute the `time' command?
Thanks all!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 01:10 PM
тАО05-15-2007 01:10 PM
Re: Writing a Menu-Driven Script
http://www.esscc.uq.edu.au/~ksteube/Bshell/#page_25
Also, 'man sh-posix' (the POSIX shell man page) has syntax examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 01:18 PM
тАО05-15-2007 01:18 PM
Re: Writing a Menu-Driven Script
...
read choice
eval ${choice}
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 03:19 PM - edited тАО10-02-2011 09:19 PM
тАО05-15-2007 03:19 PM - edited тАО10-02-2011 09:19 PM
Re: Writing a Menu-Driven Script
JRF has the command being entered by the user. Is this what you want? (The user could enter "rm -rf /". )-:
In my reply to your same question in:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=993074
http://h30499.www3.hp.com/t5/Languages-and-Scripting/Sample-Shell-Script-with-Menu/m-p/3712343
I had:
I was going to say you use the select builtin. And if you look at Pete's example, it does that.
> echo "+ Enter for the current time"
> read choice
> case ${choice} in
One could do that. For my select example:
echo "Select the compare mode:"
select DT in "-r" "-b" "-a"; do
break
done
if [ "$DT" = "" ]; then
DT="-r"
fi
This prints:
Select the compare mode:
1) -r
2) -b
3) -a
#?
The user types in a number, 1 to 3.
The logic above says if an invalid number is typed, set it to the "-r" choice.
> If the user selects, how would you write this in the script to execute the time command?
For your case:
case ${choice} in
"") date ;;
... # other choices
*) echo "invalid choice: ${choice}" ;;
esac
- Tags:
- select