From owner-freebsd-questions@FreeBSD.ORG Thu Oct 28 16:17:17 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 833DC106566B for ; Thu, 28 Oct 2010 16:17:17 +0000 (UTC) (envelope-from sterling@camdensoftware.com) Received: from wh2.interactivevillages.com (wh2.interactivevillages.com [75.125.250.34]) by mx1.freebsd.org (Postfix) with ESMTP id 46C418FC1C for ; Thu, 28 Oct 2010 16:17:17 +0000 (UTC) Received: from 174-21-106-233.tukw.qwest.net ([174.21.106.233] helo=_HOSTNAME_) by wh2.interactivevillages.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1PBV1s-0001eC-Ni for freebsd-questions@freebsd.org; Thu, 28 Oct 2010 09:08:41 -0700 Received: by _HOSTNAME_ (sSMTP sendmail emulation); Thu, 28 Oct 2010 09:17:12 -0700 Date: Thu, 28 Oct 2010 09:17:12 -0700 From: Chip Camden To: FreeBSD Questions Message-ID: <20101028161712.GC73337@libertas.local.camdensoftware.com> Mail-Followup-To: FreeBSD Questions References: <20101027212841.GA67716@guilt.hydra> <20101028151148.GB73337@libertas.local.camdensoftware.com> <20101028160110.GA71713@guilt.hydra> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZwgA9U+XZDXt4+m+" Content-Disposition: inline In-Reply-To: <20101028160110.GA71713@guilt.hydra> User-Agent: Mutt/1.4.2.3i Company: Camden Software Consulting URL: http://camdensoftware.com X-PGP-Key: http://pgp.mit.edu:11371/pks/lookup?search=0xD6DBAF91 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - wh2.interactivevillages.com X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - camdensoftware.com Subject: Re: [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: Thu, 28 Oct 2010 16:17:17 -0000 --ZwgA9U+XZDXt4+m+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Quoth Chad Perrin on Thursday, 28 October 2010: > On Thu, Oct 28, 2010 at 08:11:48AM -0700, Chip Camden wrote: > >=20 > > Here's a way to do what you're wanting to do. Unfortunately, it isn't a > > generalized, single construct: > >=20 > > #!/bin/sh > > if [ $# -ge 1 ];then > > exec cat $@ | $0 > > exit > > fi > >=20 > > while read data; do > > echo $data > > done > >=20 > > My lame attempts to generalize the first paragraph into an alias, > > function, or shell script have met with disappointment. >=20 > I was hoping for a generalized, simple idiom for this, rather than > needing to implement it myself, for demonstration purposes (and for easy > reuse later, of course). Your solution does not exactly fit my > preferences for simplicity, but I might include it in an article I'm > writing anyway. It's simple and readable enough that it should not > clutter up the article much. >=20 > I tested it for some simple use cases, and it works well. Thanks for > saving me a little trouble. >=20 > --=20 > Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] You're most welcome. Perhaps someone with more sh fu can transform the 'if' paragraph into a one-liner at least. When I tried to do so, I got an unexpected ; error. --=20 Sterling (Chip) Camden | sterling@camdensoftware.com | 2048D/3A978E4F http://camdensoftware.com | http://chipstips.com | http://chipsquips= .com --ZwgA9U+XZDXt4+m+ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iQEcBAEBAgAGBQJMyaIIAAoJEIpckszW26+RORoH/3fQm9EqcOMxITAgUpYXGMQx NLWSQ3Xv6sT5uCWe7o3/a+WWHyrzFjPt86UjI2xSdm0xcsRi+Cm8SZpJ7cVjPELl 7PXtd01D9+Pgc8M2/AOOo3Hsr/tLtYsO5blljMNXcC1yNuUpuyKqvv8gjyCT9Tac yBqnI4IUOUNeIum6eD/kZsmLwpUVUGnONGuuL7JyX0Jo2zi8KiSQWKc/NIhvb7NM DuVhZoD6EH1ffSIHNh+nqkvlFXyOoKv3JmwFh3nu7KkSslEEEYl1UT/nQosyaTc0 aRAwvehJASKGw5XZ0ick9GKlo7libx2l4HQdib7fhCO8nYe4gW2nIZVv8Is4R2E= =Q3g0 -----END PGP SIGNATURE----- --ZwgA9U+XZDXt4+m+--