# [BASH] How to change from reading from a file to reading from STDIN in while loop?

1. Jun 4, 2012

### zeion

Hi,

So I can read from a file by doing:

...
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.

2. Jun 4, 2012

### oli4

Re: [BASH] How to change from reading from a file to reading from STDIN in while loop

Hi zeion,
is this what you are looking for ?

3. Jun 4, 2012

### gsal

Re: [BASH] How to change from reading from a file to reading from STDIN in while loop

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?