![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ls while read loop - internal read picking up wrong input | dkieran | Shell Programming and Scripting | 2 | 05-14-2007 03:02 PM |
| While read loop and rsh | 104234 | UNIX for Advanced & Expert Users | 1 | 01-15-2006 11:53 AM |
| input inside while read loop | jhansrod | Shell Programming and Scripting | 3 | 08-13-2005 10:46 AM |
| Nested while read line loop | Rakker | Shell Programming and Scripting | 7 | 06-24-2005 07:42 AM |
| read inside a while loop | dta4316 | UNIX for Dummies Questions & Answers | 3 | 05-21-2005 10:53 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
Please explain read in a while loop
I have a script which tries to read input from a user for every value read from a file. The input file is
Code:
#> more testfile TEST1 | D200 | 12345601 | | ABC company | m TEST2 | D201 | 12345602 | | ABC company | m Code:
while read line do read test?"Enter a Value:" done < testfile Code:
#>test.sh #> Jerardfjay ![]() |
|
||||
|
Quote:
I need to read input from user for every line that I read from the testfile. How would I accomplish that. Your example does not involve the loop reading from a file as well as reading user input within the loop of reading from a file. I use the $line variable within the loop to extract data that I require for other purposes. Code:
while read line
do
var1=$(echo "${line}" | awk -F "|" '{print $2}' | sed -e 's/^ *//g;s/ *$//g')
read input?"Enter value :" <<<---- This read does not work
echo $input
# do some processing with $var1 and $input and continue
done < testfile
Jerardfjay Last edited by jerardfjay; 01-11-2006 at 05:27 PM.. Reason: clarification of reply |
|
||||
|
Code:
while read line do read test?"Enter a Value:" done < testfile In the above code, in the first line, it says read line.. it reads the first line from the testfile and puts it into the variable called line, again when you say read test, it actually reads the second line from testfile and puts it into the variable test.. it won't take the input from the keyboard because you have given the input as testfile by specifying the "<". use this code #!/usr/bin/ksh IFS=" " for line in $(< testfile) do echo $line echo "Enter value :" read a done Last edited by mahendramahendr; 01-11-2006 at 05:44 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|