Computing.Net > Forums > Unix > Taking input from file and user

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.

Taking input from file and user

Reply to Message Icon

Name: smacv
Date: March 7, 2005 at 06:47:56 Pacific
OS: SUN
CPU/Ram: unknown
Comment:

Folks,
I have a while loop that is taking input from a file

while read variable
do
.
.
.
done < filename.txt

However during the loop I am trying to take some user input

print "....[y/n]" read $var

However the read command takes the input from the input file.

What should I be doing?




Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: March 7, 2005 at 07:36:16 Pacific
Reply:

exec 3< filename.txt

while read -u3 filevar
do
echo "For $filevar, enter uservar: \c"
read uservar
echo "filevar=$filevar uservar=$uservar"
done


0

Response Number 2
Name: smacv
Date: March 7, 2005 at 08:20:51 Pacific
Reply:

Thanks - worked a treat. Now I just read to nuderstand what exec and read -u does?

Any good reading sources online?


0

Response Number 3
Name: Jim Boothe
Date: March 7, 2005 at 09:28:49 Pacific
Reply:

There are a lot of good references for unix in general on this forum. Maybe someone will provide a good reference for this.

For the read command, you can do "man read".

The exec command changes the designated input or output file. For example, you can override the default stdout and stderr destination by putting the following at the start of a script:

exec > myscript.log 2>&1

Now, all stdout and stderr will be sent to myscript.log by default. This is much cleaner and better than a lot of individual redirects throughout your script. And even with this directive in effect, you can still force output to the screen with:

echo 'Enter reply: ' > /dev/tty

For your solution, we force the while-loop to use a non-standard unit# (file#).


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Taking input from file and user

Input from file, create multi-users www.computing.net/answers/unix/input-from-file-create-multiusers/6845.html

how can i get the input from user www.computing.net/answers/unix/how-can-i-get-the-input-from-user/5641.html

input to a program from a file www.computing.net/answers/unix/input-to-a-program-from-a-file/5021.html