From owner-freebsd-questions@FreeBSD.ORG Thu Oct 28 17:42:16 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 7217B106566C for ; Thu, 28 Oct 2010 17:42:16 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 2E8AB8FC0A for ; Thu, 28 Oct 2010 17:42:15 +0000 (UTC) Received: from r55.edvax.de (port-92-195-16-227.dynamic.qsc.de [92.195.16.227]) by mx02.qsc.de (Postfix) with ESMTP id 25189296B8; Thu, 28 Oct 2010 19:42:14 +0200 (CEST) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id o9SHexnA001881; Thu, 28 Oct 2010 19:40:59 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Thu, 28 Oct 2010 19:40:59 +0200 From: Polytropon To: FreeBSD Questions 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> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: Chip Camden Subject: Re: [OT] writing filters in sh X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Oct 2010 17:42:16 -0000 On Thu, 28 Oct 2010 19:28:26 +0200, Polytropon wrote: > On Thu, 28 Oct 2010 09:17:12 -0700, Chip Camden 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, ...