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

input script

Status
Not open for further replies.

abovebrd

IS-IT--Management
May 9, 2000
690
0
0
US
<br>I need to find an easy way to input 4 lines of text into another file. The catch is that I need to do this from a menu interface. Most of my users are not real profceint unix user. Shell commands are not an option. It has to come from a script.<br><br>How would I create a script that prompts for 4 lines of text. The text would then be appened to a file.<br><br>The part that I am having trouble with is how do I prompt for the Text input.<br><br>Enter text:<br>1.<br>2.<br>3.<br>4.<br><br>Any ideas <br><br> <p>Danny Daniels<br><a href=mailto:dannyd@aboveboardelectronics.com>dannyd@aboveboardelectronics.com</a><br><a href= > </a><br>
 
Danny,<br><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>
 
Danny,<br><br>A simple way to achieve what you desire would be to create a script containing the following:<br><br>------------------------------- 8&lt; ---------------------------<br><FONT FACE=monospace>#!/bin/ksh<br><br>echo &quot;Enter text:&quot;<br>echo -n &quot;1. &quot;<br>read LINE1<br>echo -n &quot;2. &quot;<br>read LINE2<br>echo -n &quot;3. &quot;<br>read LINE3<br>echo -n &quot;4. &quot;<br>read LINE4<br><br>echo $LINE1 &gt;&gt; filename<br>echo $LINE2 &gt;&gt; filename<br>echo $LINE3 &gt;&gt; filename<br>echo $LINE4 &gt;&gt; filename</font><br>------------------------------- 8&lt; ---------------------------<br><br>You could also generalise it with a 'for' loop so that it is easily expandable.<br><br>Annihilannic.<br>
 
Thanks ChristopherD and Annihilannic,<br><br>Both Ideas worked extremely well.<br><br>Thanks for the Help<br><br>-Danny <p>Danny Daniels<br><a href=mailto:dannyd@aboveboardelectronics.com>dannyd@aboveboardelectronics.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top