Date: Thu, 28 Oct 2010 10:59:41 -0700 From: Chip Camden <sterling@camdensoftware.com> To: freebsd-questions@freebsd.org Subject: Re: [OT] writing filters in sh Message-ID: <20101028175941.GF73337@libertas.local.camdensoftware.com> In-Reply-To: <20101028175142.21E2CBF81@kev.msw.wpafb.af.mil> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <sterling@camdensoftware.com> 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101028175941.GF73337>