Date: Mon, 7 Jan 2008 23:31:10 -0800 From: Gary Kline <kline@magnesium.net> To: Jon Hamilton <hamilton@pobox.com> Cc: Paul Procacci <pprocacci@datapipe.com>, Gary Kline <kline@magnesium.net>, FreeBSD Mailing List <freebsd-questions@FreeBSD.ORG> Subject: Re: is there a /bin/sh method to tell the ending of a file Message-ID: <20080108073110.GB20085@thought.org> In-Reply-To: <20080108060118.GF1965@woodstock.nethamilton.net> References: <20080108051058.GA19698@thought.org> <20080108053408.GA95218@procacci.kicks-ass.org> <20080108060118.GF1965@woodstock.nethamilton.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jan 08, 2008 at 12:01:18AM -0600, Jon Hamilton wrote: > } On Mon, Jan 07, 2008 at 09:10:58PM -0800, Gary Kline wrote: > } Paul Procacci <pprocacci@datapipe.com>, 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 :) > You may be right since lots of us toss bats or brickbats over seriously inconsequential things! I'm an agnostic--or possibly a gnostic--when it comes to the [*koff*] ``religious args'' and so forth. ....I like your first method since I'm reading a great book called AWK AND SED. Irecommend it to anybody who's into the fine points of sed. I keep forgetting about the "\1" in sed, but still I'm not that far alongto have come up with your expression, :-) Impressive,thanks! The case/esac block would have occured to me eventully, but not tonight. Anywy, the if/predicate case is what I want. So I can gunzip, then hand off to my cdrecord line and re-gzip. Plus, yell at me ... or whatever. enjoy! gary > -- > > Jon Hamilton > hamilton@pobox.com -- Gary Kline Seattle BSD Users' Group (seabug) | kline@magnesium.net Thought Unlimited Org's Alternate Email Site http://www.magnesium.net/~kline To live is not a necessity; but to live honorably...is a necessity. -Kant
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080108073110.GB20085>