[SLUG] bash and stdin

From: Mike Branda (realraccoon@tampabay.rr.com)
Date: Sat Jul 28 2007 - 16:01:54 EDT


Slug,

I have a bash script I'm playing with that reads input from a pipe. I
want to add some error handling to the effect of when the script is
called by itself and no information is piped to it, it exits and/or
exits and complains. The problem I have is that I'm doing a "while read
line do" and if there's no data coming in, it sits there waiting on the
read. I've tried to use a if [ -s /dev/stdin ] conditional before the
while but to no success.

Does anybody have an idea on this or on how to test stdin?

examples:

:~>cat lines.txt | myscript.sh -takeinput
I've got input... echoing
line 1
line 2
line 3
:~>
:~>myscript.sh -takeinput
(sits here waiting for input or ctrl-c)

Thanks!

Mike Branda Jr.

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:12:47 EDT