From owner-freebsd-questions@FreeBSD.ORG Thu Oct 28 17:59:46 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 91F8F1065674 for ; Thu, 28 Oct 2010 17:59:46 +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 548928FC32 for ; Thu, 28 Oct 2010 17:59:46 +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 1PBWd3-000191-Ez for freebsd-questions@freebsd.org; Thu, 28 Oct 2010 10:51:10 -0700 Received: by _HOSTNAME_ (sSMTP sendmail emulation); Thu, 28 Oct 2010 10:59:41 -0700 Date: Thu, 28 Oct 2010 10:59:41 -0700 From: Chip Camden To: freebsd-questions@freebsd.org Message-ID: <20101028175941.GF73337@libertas.local.camdensoftware.com> Mail-Followup-To: freebsd-questions@freebsd.org References: <20101027212841.GA67716@guilt.hydra> <20101028151148.GB73337@libertas.local.camdensoftware.com> <20101028160110.GA71713@guilt.hydra> <20101028161712.GC73337@libertas.local.camdensoftware.com> <20101028175142.21E2CBF81@kev.msw.wpafb.af.mil> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="L2Brqb15TUChFOBK" Content-Disposition: inline In-Reply-To: <20101028175142.21E2CBF81@kev.msw.wpafb.af.mil> 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 17:59:46 -0000 --L2Brqb15TUChFOBK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Quoth Karl Vogel on Thursday, 28 October 2010: > >> On Thu, 28 Oct 2010 09:17:12 -0700,=20 > >> Chip Camden said: >=20 > C> Perhaps someone with more sh fu can transform the 'if' paragraph into a > C> one-liner at least. When I tried to do so, I got an unexpected ; erro= r. >=20 > Try this: >=20 > #!/bin/sh > test $# -ge 1 && cat $@ | exec $0 && exit 0 >=20 > IFS=3D$'\n' > while read data; do > echo "$data" > done > exit 0 >=20 > Resetting IFS is only necessary if you want to preserve whitespace in > each line. Putting $data in quotes prevents any shell metacharacters > from being expanded. >=20 > --=20 > Karl Vogel I don't speak for the USAF or my company > Sign in a New York drugstore: "We dispense with accuracy" > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" Much better than my latest version, which always invokes $0. As an alias: alias inargs=3D'[ $# -ge 1 ] && cat $@ | exec $0 && exit' #!/bin/sh inargs while read data; do echo $data; done --=20 Sterling (Chip) Camden | sterling@camdensoftware.com | 2048D/3A978E4F http://camdensoftware.com | http://chipstips.com | http://chipsquips= .com --L2Brqb15TUChFOBK Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iQEcBAEBAgAGBQJMyboNAAoJEIpckszW26+RnAYIALo55fYoc4ZL5sfKa+pRbvrj /w4qyDE1cWXv8uXkpi7TbJrXNJgTBxj8eZss/v8zL8K7Cli9qWOdEmucy7EsXe8h A3XZcX0pV7v4bOVx8w5vUcrfdE+Os8Ih7NlQL/cxRI/y4nGrYbZ+XzCUwkLIezaZ NA1eSwBBJMsDWOm1GktdZiXXSGERxFc2WBycws1mIA93Wg1sA9SxRbTDXV4eBdqY /UWJnE/43DiIOkv9DKfT2t04Gzdp5eOhjUtR8+SJAO/IaK1Mpyf1i26xURscgL9e 7u6pd04inWpMUVEC19p9eKnQ3QNj223MLgpIMQcEYvXU0rCTAoDkPToHkWNRs6A= =YZIG -----END PGP SIGNATURE----- --L2Brqb15TUChFOBK--