[OT] writing filters in sh

Chad Perrin perrin at apotheon.com
Wed Oct 27 21:34:12 UTC 2010


I know that in sh you can get the contents out of files specified as
command line arguments:

    while read data; do
      echo $data
    done <$@

I know you can also get the contents of files from pipes and redirects:

    while read data; do
      echo $data
    done

In Perl, you can use a single construct to do both and, unlike the first
sh example, it can also take multiple filenames as arguments and
effectively concatenate their contents:

    while (<>) {
      print $_;
    }

I'm not exactly an *expert* in sh, in part because when things start
getting "interesting" while I'm writing shell scripts I tend to just use
a more robust language like Perl.  Please let me know if there's some way
to use a simple idiom like the Perl example to get the same results in
sh.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20101027/5e2c866e/attachment.pgp


More information about the freebsd-questions mailing list