Date: Thu, 28 Oct 2010 19:40:59 +0200 From: Polytropon <freebsd@edvax.de> To: FreeBSD Questions <freebsd-questions@freebsd.org> Cc: Chip Camden <sterling@camdensoftware.com> Subject: Re: [OT] writing filters in sh Message-ID: <20101028194059.c9c643e3.freebsd@edvax.de> In-Reply-To: <20101028192826.d3211524.freebsd@edvax.de> References: <20101027212841.GA67716@guilt.hydra> <20101028151148.GB73337@libertas.local.camdensoftware.com> <20101028160110.GA71713@guilt.hydra> <20101028161712.GC73337@libertas.local.camdensoftware.com> <20101028192826.d3211524.freebsd@edvax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 28 Oct 2010 19:28:26 +0200, Polytropon <freebsd@edvax.de> wrote: > On Thu, 28 Oct 2010 09:17:12 -0700, Chip Camden <sterling@camdensoftware.com> wrote: > > 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. > > Not tested, but this should do the trick: > > #!/bin/sh > if [ $# -ge 1 ] && ( exec cat $@ | $0; exit ) > while read data; do echo $data; done Attention - does NOT work! Maybe my sh fu is just shhh foo. :-) #!/bin/sh [ $# -ge 1 ] && ( exec cat $@ | $0; exit ) while read data; do echo $data; done THIS is better. You can see that "if" has been removed, leaving a call to the program "test" (/bin/test is /bin/[), as long as sh does not use a built-in test or [ mechanism. The "if" is not neccessary here, as the if-then-fi construct is implicated by the use of &&. Tested. Works. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101028194059.c9c643e3.freebsd>