Reading from stdin Instead of a File

  • Thread starter Thread starter zeion
  • Start date Start date
  • Tags Tags
    File Reading
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
zeion
Messages
455
Reaction score
1
Hi,

So I can read from a file by doing:

while read line; do
...
done<$fileame

Is it possible to change to reading from stdin instead of that file by changing the $filename variable instead of writing a new loop without a done< argument?

Thanks.
 
Physics news on Phys.org


Hi zeion,
is this what you are looking for ?
 


Hhhhmmm...I think you should be going the other way around.

I have not tested any of this and don't have time at the moment, but maybe you should test WITHOUT "done < $filename" in the first place...

you see "<" was invented, precisely to make a file look like is coming from standard input...not to make standard input look like a file..

...in other words, what I am saying is that you finish your while loop with simply "done" and THEN, if you want to feed it standard input, well, you simply start typing AND if you want to feed it with an input file, well, you run your bash script and follow it with "< filename"

would that work for you?