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

a bit of korn shell scripting help ... anyone? 1

Status
Not open for further replies.

mckarl

Programmer
May 5, 1999
147
GB
ok, check dis owt..<br><br><br>#!/bin/ksh<br>#<br># Boring nicey nicey stuff<br>#<br>clear<br>echo &quot;Welcome to karls ^[[5m MAD ^[[0m party&quot;<br>echo &quot;please enter your name: \c&quot;<br>read user_name<br>echo &quot;Well, $user_name hope you have fun!&quot;<br>sleep 4<br>#<br># main menu<br>#<br>clear<br>echo &quot;\t\t1. ak47 demolishion&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2. have a sandwich\n&quot;<br>echo &quot;\t\t3. talk to pretty girl&nbsp;&nbsp;&nbsp;&nbsp;3. get blind drunk\n&quot;<br>echo &quot;\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:\c&quot;<br>read what_to_do<br>#<br># conditions<br>#<br>case what_to_do in <br>#<br># and the program goes on.<br>#<br><br><br><br>#################~~~~~~~~~~~~~~~~~############<br><br>what I want to do, is allow the user to input a letter, and it doesnt need a return-code. C what i mean? another thing is, being able to DRAW with a shell script, so i could put a pretty box or something around.<br><br>know what i mean?<br><br>like - screen 1:<br><br>+++++++++++++++++++++<br>+ input here: [ ]&nbsp;&nbsp;&nbsp;+ # where the input goes<br>+++++++++++++++++++++<br><br>can anyone help with the above?<br>1. to accept characters without the need for a return code<br>2. draw screen, then again over the top of it, or prompting some type of character location?<br>This would be most useful in a korn shell environment, i know it's possible in a C shell env. so if you could help with either, i would be most greatful!!!!!<br><br><br>Thanks for any help!! ... karl!<br><br><br><br><br><br><br><br><br><br><br><br><br> <p> Karl<br><a href=mailto:mc_karl@yahoo.com>mc_karl@yahoo.com</a><br><a href= > </a><br> ~ ~ ~ ~<br>
K A R L<br>
~ ~ ~ ~
 
Karl -<br>You can 'draw' a screen using a clear command and some print or echo/print commands like so:<br><br>clear<br>print &quot;************************************************&quot;<br>print &quot;**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hello &quot;$LOGNAME&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**&quot;<br>print &quot;** Please select 1 to do something&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**&quot;<br>print &quot;** Please select 2 to do something else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**&quot;<br>print &quot;************************************************&quot;<br><br>The menu can be done with a 'select' statement, Your PS3 prompt and a do loop like so:<br><br>PS3='Enter Choice? '<br><br>select choice in 'Something' 'Something else' <br><br>do<br>&nbsp;&nbsp;case $REPLY in<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ) something_func ;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 ) somethingelse_func ;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x ) break ;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* ) print &quot;Invalid choice. Please try again.&quot; ;;<br>&nbsp;&nbsp;esac<br>done<br><br>The select statement builds a menu for you, the REPLY holds the user's answer.&nbsp;&nbsp;If '1' is pressed the something_func is preformed, if '2' is pressed the somethingelse_func is performed, 'x' will terminate the script (as well as &lt;cntl&gt; d), If anything else is entered, the wild card '*' will pick it up and display the &quot;Invalid choice&quot; message.&nbsp;&nbsp;The PS3 prompt is used by the select statement to prompt the user.&nbsp;&nbsp;<br><br>I hope I haved answered your question!<br> <p>Christopher Devenny<br><a href=mailto:c_devenny@yahoo.com>c_devenny@yahoo.com</a><br><a href= > </a><br>
 
You might like to consider using the <b>dialog</b> command.<br><br>McH
 
Check out the <FONT FACE=monospace><b>tput cup x y</font></b> command for box drawing.<br><br> <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
If you'd like &quot;hot-key&quot; behavior, where the input key is not echoed and the user doesn't need to hit Enter, try the following:<br><FONT FACE=monospace><b><br>stty raw -echo<br>key=$(dd if=$(tty) ibs=1 count=1 2&gt;/dev/null)<br>stty -raw echo<br></b></font><br> <p>Rod Knowlton<br><a href=mailto:jrknowlton@visto.com>jrknowlton@visto.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top