Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Oct 2010 15:28:41 -0600
From:      Chad Perrin <perrin@apotheon.com>
To:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   [OT] writing filters in sh
Message-ID:  <20101027212841.GA67716@guilt.hydra>

next in thread | raw e-mail | index | archive | help

--qDbXVdCdHGoSgWSk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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.

--=20
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

--qDbXVdCdHGoSgWSk
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAkzImYkACgkQ9mn/Pj01uKW89QCdHcCWcv8cYANxcEp9Nx2r1xBW
ABcAnRhPowm9vcm6YuUmNCIKGpKhDHTv
=dNVn
-----END PGP SIGNATURE-----

--qDbXVdCdHGoSgWSk--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101027212841.GA67716>