[aklug] Re: noob scripting question -- file input/output

From: Royce Williams <royce@alaska.net>
Date: Fri Oct 31 2008 - 13:10:31 AKDT

Christopher Howard wrote:
> Forgive the newbie question.

We've all been there! And we are all there now -- just at different
doorways. ;-)

> Say I've got a C program called foo, and
> foo takes input from stdin, processes it, and prints results to stdout.

Many Unix-like commands fall along these lines - is there a specific one
you're asking about, or just exploring/learning the theory?

> I know that in a shell I can use files for stdin/stdout like this
> (because it worked when I tried):
>
> $ cat datain | foo | cat > dataout
>
> Can I get the same results without using cat?

Did your test succeed? ;-)

Removing one of these felines should be easy ... I suspect that

$ cat datain | foo > dataout

... would usually work. Many programs also directly accept a file as
"the something to operate on", as in

$ foo datain > dataout

... though this is not always the case. The "list of things to do", the
"list of ways to do it" and the "list of things to do it to" can be
separated in a number of ways. The Unix way is usually to assume that
anything that isn't a flag is the start of stuff that is the target of
your activities.

grep happily takes flags, but then the first time you pass it something
that isn't a flag, it assumes that that's the thing to look for, and the
next thing where to look:

royce@heffalump$ grep FreeBSD /etc/motd >/var/tmp/osver
royce@heffalump$ cat /var/tmp/osver
FreeBSD 6.4-RC1 (GENERIC) #0: Sun Oct 5 11:11:02 UTC 2008

Not sure if that answers your question or not. Any other pets you need
to have removed? ;-) I'm more of a dog person, myself, though I am
quite fond of the friendly subspecies of cat. Now that I think about
it, it's the friendly that matters more than the species.

Royce
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Fri Oct 31 13:10:46 2008

This archive was generated by hypermail 2.1.8 : Fri Oct 31 2008 - 13:10:46 AKDT