in reply to Re: Re: Re: Test for standard input
in thread Test for standard input
You might consider looking at the problem a little differently. Frankly, your error, "No input found," makes very little sense. When called as simply
the input, stdin, is still available to the program. What's missing is the pattern to search for in the input.$ grep
Instead of going to all the trouble to test for a tty, you might find it's preferable to simply check to make sure there is at least one argument. If there is exactly one argument, it is the pattern and stdin is the input. If there are more than one then the subsequent ones are filenames of the files you wish to use for input. That way, it is only an error when no arguments are supplied. This is how grep(1) works so the behavior will be familiar even to users who have never used your program before.
Also, you might want to add these to your test cases:
$ grep < some_file $ cat | grep
-sauoq "My two cents aren't worth a dime.";
|
|---|