From owner-freebsd-questions@FreeBSD.ORG Wed Oct 27 21:34:12 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BB972106566B for ; Wed, 27 Oct 2010 21:34:12 +0000 (UTC) (envelope-from perrin@apotheon.com) Received: from cpoproxy3-pub.bluehost.com (cpoproxy3-pub.bluehost.com [67.222.54.6]) by mx1.freebsd.org (Postfix) with SMTP id 873FF8FC1F for ; Wed, 27 Oct 2010 21:34:12 +0000 (UTC) Received: (qmail 24036 invoked by uid 0); 27 Oct 2010 21:34:11 -0000 Received: from unknown (HELO box543.bluehost.com) (74.220.219.143) by cpoproxy3.bluehost.com with SMTP; 27 Oct 2010 21:34:11 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=apotheon.com; h=Date:From:To:Subject:Message-ID:Mail-Followup-To:Mime-Version:Content-Type:Content-Disposition:User-Agent:X-Identified-User; b=RjdXaE6V99/zAAchNi58Ga9fZQDRfmMQSv+cJaxk6DompJuHkK5ZHQo4Sey5irPRgeSt6gSuGSo0zGHtJGqcEJx/elqx3IEeAMwl+bCmznt4P8v+7QsyFORCChVi7aoa; Received: from c-24-8-180-234.hsd1.co.comcast.net ([24.8.180.234] helo=kukaburra.hydra) by box543.bluehost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1PBDdK-0004a9-GY for freebsd-questions@freebsd.org; Wed, 27 Oct 2010 15:34:11 -0600 Received: by kukaburra.hydra (sSMTP sendmail emulation); Wed, 27 Oct 2010 15:28:41 -0600 Date: Wed, 27 Oct 2010 15:28:41 -0600 From: Chad Perrin To: FreeBSD Questions Message-ID: <20101027212841.GA67716@guilt.hydra> Mail-Followup-To: FreeBSD Questions Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qDbXVdCdHGoSgWSk" Content-Disposition: inline User-Agent: Mutt/1.4.2.3i X-Identified-User: {2737:box543.bluehost.com:apotheon:apotheon.org} {sentby:smtp auth 24.8.180.234 authed with ren@apotheon.org} Subject: [OT] writing filters in sh X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Oct 2010 21:34:12 -0000 --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--