Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Writing a line based filter that exits when no input

View Parsed - Show only message text

Path: g2news1.google.com!news1.google.com!news3.google.com!feeder.news-service.com!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!news.eternal-september.org!not-for-mail
From: Barry Margolin <bar...@alum.mit.edu>
Newsgroups: comp.unix.programmer
Subject: Re: Writing a line based filter that exits when no input
Date: Sat, 04 Jul 2009 02:23:18 -0400
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <barmar-69A8A0.02231804072009@news.eternal-september.org>
References: <pan.2009.07.04.06.09.58@tznvy.pbz>
X-Trace: news.eternal-september.org U2FsdGVkX19BOuHN0OG8iCBszI3ZQNQCjIu8Tt+CM9HZ4R1BRPcbG7ZDe1NtwUdg7FsUgHNLw7GaPe/B4JKyBN0mZVijBhqrwR9womlk9xLzYuSJuUzYixp2YcQW8G08+17hNlJQi60=
X-Complaints-To: abuse@eternal-september.org
NNTP-Posting-Date: Sat, 4 Jul 2009 06:27:00 +0000 (UTC)
X-Auth-Sender: U2FsdGVkX1+mD3vwt57eqYFGdswE6x8TGPPQZYKpqPg=
Cancel-Lock: sha1:nqS5ZEb4myB59VeduqLupwfTYEc=
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Mail-Copies-To: nobody

In article <pan.2009.07.04.06.09...@tznvy.pbz>,
 Anand Hariharan <znvygb.nanaq.unevun...@tznvy.pbz> wrote:

> Am writing a line-based  filter a la sed or tr. What I  would like it to
> do, however, is if there is no input at start-up, it should present some
> usage information and exit.
> 
> E.g., 
> 
> $ MyLineFilter < TextFile # OK
> 
> $ Some Command | MyLineFilter # OK
> 
> $ MyLineFilter
> MyLineFilter: Did not find any text to process.  Exiting.
> 
> $ echo $?
> 1
> 
> $ MyLineFilter Command Line Args # Undecided what to do here ...
> 
> 
> Would appreciate some ideas on how to implement this.
> 
> Currently, am writing the usage information to stderr (unconditionally), 
> but the executable waits for input until it finds EOF.

In the third case, there IS input -- standard input is connected to the 
terminal, and the user is supposed to type the input.

If you don't want to take input from the terminal, you can use:

if test -t
then echo $0: Did not find any text to process. Exiting. >&2
     exit 1
fi

-- 
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google