[wplug] Line-by-line input from stdin, from a bash script ?
Pat Barron
pat at lectroid.com
Tue Oct 15 22:49:10 EDT 2013
On 10/15/2013 12:51 PM, Eric Cooper wrote:
> On Mon, Oct 14, 2013 at 12:49:14PM -0400, Pat Barron wrote:
>> Does anyone have any favorite methods of doing "line at a time"
>> input from stdin, using a bash script?
> line=$(head -1)
>
I didn't even know that's something you can do... ;-)
I actually started out trying to use something like this, using shell
backquotes - but somehow, doing it that way either consumes all of stdin
(even though it returns only the first line), or closes stdin, and I
could not get anything other than the first line. This works, though.
And, after some experimentation, it looks like "read -r" works
equivalently - and neither one chops trailing whitespace, or squashes
multiple repeating spaces down to one space (both of which I was afraid
could happen). I was afraid I was going to have to tinker around with
$IFS to get it to leave the spaces alone, but I didn't even need to do
that (using either the "read -r" method, or the "$()" method).
I actually have my toy web server serving static HTML content, and
reading/setting cookies at this point. The next challenge, whenever I
get a little more spare time, is to see if I can make HTTP "POST"
requests do something interesting. It's just a "fun" project, it's
interesting mainly just to demonstrate that it's possible at all... ;-)
Thanks to everyone who's provided suggestions!
(BTW, after spending a bunch of time testing things ... turns out that
typing "GET / HTTP/1.1", over and over again, gets kind of annoying
after a while.... ;-) )
--Pat.
More information about the wplug
mailing list