The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading input from user vadharah Shell Programming and Scripting 2 03-09-2008 06:35 AM
AWK set FILENAME via user input timj123 Shell Programming and Scripting 2 02-24-2008 11:05 AM
awk user input gefa Shell Programming and Scripting 17 10-30-2007 01:01 AM
pop out screen with user input venerayan Shell Programming and Scripting 5 10-04-2007 07:00 AM
user input date gundu Shell Programming and Scripting 10 03-21-2005 11:50 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Aug 2005
Posts: 111
Question Getting user input

I am trying to create a shell (ksh) which has two "read" commands, one which reads a line from a file and another which is inside a loop that reads user input from a keyboard. However, the "read" command inside the loop uses the input from the file and it does not get the user input from keyboard.

Code:
$ more readtest.ksh
#!/bin/ksh

echo "AAA\nBBB\nCCC" > file

while read line
do

     echo "Enter word:"
     read word
     echo "$line $word"

done < file
Could someone please tell me how to fix the shell above to get user input from keyboard?

Any help will be appreciated.

Steve
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-15-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,448
Code:
read word < /dev/tty
Reply With Quote
  #3 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
#!/bin/ksh

echo "AAA\nBBB\nCCC" > file

while read line
do

     echo "Enter word:"
     read word <&1
     echo "$line $word"

done < file
Reply With Quote
  #4 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Aug 2005
Posts: 111
Thanks anbu23 and matrixmadhan!

It worked!

Cheers
Steve
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0