From owner-freebsd-questions@FreeBSD.ORG Thu Oct 28 17:28:29 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 773431065673 for ; Thu, 28 Oct 2010 17:28:29 +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 36C0F8FC1D for ; Thu, 28 Oct 2010 17:28:28 +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 61FB81EC20; Thu, 28 Oct 2010 19:28:26 +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 o9SHSQYl001827; Thu, 28 Oct 2010 19:28:26 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Thu, 28 Oct 2010 19:28:26 +0200 From: Polytropon To: Chip Camden Message-Id: <20101028192826.d3211524.freebsd@edvax.de> In-Reply-To: <20101028161712.GC73337@libertas.local.camdensoftware.com> References: <20101027212841.GA67716@guilt.hydra> <20101028151148.GB73337@libertas.local.camdensoftware.com> <20101028160110.GA71713@guilt.hydra> <20101028161712.GC73337@libertas.local.camdensoftware.com> 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: FreeBSD Questions 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:28:29 -0000 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 The ; denotes a line break, means that you can use EITHER ; or a newline. In the original construct, if [ $# -ge 1 ]; then exec cat $@ | $0 exit fi you can change the ; into if [ $# -ge 1 ] then exec cat $@ | $0 exit fi which is often seen in scripts. In this case, no ; is required (or even allowed). The same rule applies for the while/do/done iterator. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...