Reading from stdin Instead of a File

  • Thread starter Thread starter zeion
  • Start date Start date
  • Tags Tags
    File Reading
AI Thread Summary
The discussion centers on reading input in a bash script, specifically whether it's possible to switch from reading a file to standard input by simply changing the filename variable. One participant suggests that instead of using "done < $filename," the loop should end with just "done." This allows for standard input to be provided directly when the script is run, while still permitting file input by redirecting with "< filename." The emphasis is on understanding that the "<" operator is used to make a file appear as standard input, rather than the other way around.
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.
 
Technology 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?
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top