From owner-freebsd-questions@FreeBSD.ORG Tue Jan 8 06:01:20 2008 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 277AC16A418 for ; Tue, 8 Jan 2008 06:01:20 +0000 (UTC) (envelope-from hamilton@pobox.com) Received: from hrndva-omtalb.mail.rr.com (hrndva-omtalb.mail.rr.com [71.74.56.123]) by mx1.freebsd.org (Postfix) with ESMTP id EBC0B13C43E for ; Tue, 8 Jan 2008 06:01:19 +0000 (UTC) (envelope-from hamilton@pobox.com) Received: from woodstock.nethamilton.net ([72.135.240.24]) by hrndva-omta02.mail.rr.com with ESMTP id <20080108060118.XZAG11918.hrndva-omta02.mail.rr.com@woodstock.nethamilton.net>; Tue, 8 Jan 2008 06:01:18 +0000 Received: by woodstock.nethamilton.net (Postfix, from userid 500) id 8A51225C5564; Tue, 8 Jan 2008 00:01:18 -0600 (CST) Date: Tue, 8 Jan 2008 00:01:18 -0600 From: Jon Hamilton To: Paul Procacci Message-ID: <20080108060118.GF1965@woodstock.nethamilton.net> References: <20080108051058.GA19698@thought.org> <20080108053408.GA95218@procacci.kicks-ass.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080108053408.GA95218@procacci.kicks-ass.org> Cc: Gary Kline , FreeBSD Mailing List Subject: Re: is there a /bin/sh method to tell the ending of a file X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jan 2008 06:01:20 -0000 } On Mon, Jan 07, 2008 at 09:10:58PM -0800, Gary Kline wrote: } Paul Procacci , said on Mon Jan 07, 2008 [11:34:08 PM]: } > Hi All, } > } > Is there an easy way of determing whether a string//filename ends in } > *.gz? using /bin/sh? I spend around 20 minutes cobbling together } > scripts to burn ISO files last night. Then blindly wasted one CD-R file that } > was gzipped..... tar barfs on you,but cdrecord dev=foo.gz writes } > exactly that. I'd like to add a line that yells at me, then gunzips and does } > an MD5; then writes. (In C, no prob; C lets me fly, but not /bin/sh. } > But anyway, if any guru can clue me in, thanks. I think my brain is in Maui } > for a few days. } > } Is this what you mean? } } --------------------- } #!/bin/sh } } STRING="mystring.gz" } } if [ ".gz" = "`echo \"$STRING\" | sed -n 's/.*\(\.gz\)$/\1/p'`" ]; then } echo test; } fi } } ----------------------- Works (I assume) but perhaps easier to read and more "native" might be: case "$STRING" in *\.gz) echo "Found .gz suffix" ;; *) echo "Not a .gz suffix" ;; esac Sh is a pretty versatile creature; I'm sure there are a thousand more ways all of which work, and some of which will cause religious arguments for decades :) -- Jon Hamilton hamilton@pobox.com