Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
read from user within loop
Name: sohaib102 Date: April 24, 2009 at 23:38:13 Pacific OS: ubuntu Subcategory: General
Comment:
Hi, solution in bash script ? I want to read a variable from user which is inside a while loop and that while loop takes input from a file but every time i read any variable input comes from file....
Name: nails Date: April 25, 2009 at 20:03:42 Pacific
Reply:
One method is to associate the data file with a file handle using the exec command. This script associates file handle 6 and then within the loop explicitly reads from standard input, file handle 1:
#!/bin/bash
exec 6<datafile
while read line
do
echo "$line"
echo "read input for var"
read var <&1
done <&6
The bash shell read command supports a -u option which allows reading from another file handle other than standard input:
#!/bin/bash
exec 6<datafile
while read -u 6 line
do
echo "$line"
echo "read input for var"
read var <&1
done
Summary: I'm not too good at reading from a file either, but what is CurrentSize in your SaveToFile? The file may be so big that it takes a long time for C++ to read it all. Have you tried just reading one App...
Summary: hello, i am trying to read from a file and take certain lines from the file and store them in an array. the program works fine if i store it in a variable but when i try to store it in an array it doe...
Summary: How do I get my input stream to read from the next line of input when reading from a ".dat" file. I'm using the "getline" function to do my extraction, but how do I get it to read to the next line? ...