Date: Thu, 28 Oct 2010 13:51:42 -0400 (EDT) From: vogelke+unix@pobox.com (Karl Vogel) To: freebsd-questions@freebsd.org Subject: Re: [OT] writing filters in sh Message-ID: <20101028175142.21E2CBF81@kev.msw.wpafb.af.mil> In-Reply-To: <20101028161712.GC73337@libertas.local.camdensoftware.com> (message from Chip Camden on Thu, 28 Oct 2010 09:17:12 -0700) References: <20101027212841.GA67716@guilt.hydra> <20101028151148.GB73337@libertas.local.camdensoftware.com> <20101028160110.GA71713@guilt.hydra> <20101028161712.GC73337@libertas.local.camdensoftware.com>
next in thread | previous in thread | raw e-mail | index | archive | help
>> On Thu, 28 Oct 2010 09:17:12 -0700, >> Chip Camden <sterling@camdensoftware.com> said: 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 ; error. Try this: #!/bin/sh test $# -ge 1 && cat $@ | exec $0 && exit 0 IFS=$'\n' while read data; do echo "$data" done exit 0 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. -- Karl Vogel I don't speak for the USAF or my company Sign in a New York drugstore: "We dispense with accuracy"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101028175142.21E2CBF81>