Re: is there a /bin/sh method to tell the ending of a file

2008-01-08 Thread Paul Procacci
On Mon, Jan 07, 2008 at 11:41:35PM -0800, Gary Kline wrote:
 On Mon, Jan 07, 2008 at 11:34:08PM -0600, Paul Procacci wrote:
  Is this what you mean?
  
  -
  #!/bin/sh
  
  STRING=mystring.gz
  
  if [ .gz = `echo \$STRING\ | sed -n 's/.*\(\.gz\)$/\1/p'` ]; then
   echo test;
  fi
  
  ---
  
  ~Paul
  
 
   Sorry.  You get the credit for the predicate expression; Jon had the 
   simpler 
   (and more readable:) one.But yours is warm+fuzzy in it's cleverness
   :-)
 
   gary
 
 
 
 -- 
 Gary Kline  Seattle BSD Users' Group (seabug)  | [EMAIL PROTECTED]
 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
 
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]

Quite truthfully, I forget a lot about case/esac most of the time.  It always
seems to elude me.  I guess it doesn't help that I'm a sed mongrel.

And for what it's worth, I agree that what I provided wasn't pretty, but at
least it gives everyone something to stare at for a while.  ;P

Have a good night all!

~Paul
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: is there a /bin/sh method to tell the ending of a file

2008-01-08 Thread Christian Baer
On Tue, 8 Jan 2008 02:27:29 -0600 Paul Procacci wrote:

 And for what it's worth, I agree that what I provided wasn't pretty, but at
 least it gives everyone something to stare at for a while.  ;P

Great, just like a bad accident on a major road. It isn't pretty, but you
just have to look. :-

Regards,
Chris
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: is there a /bin/sh method to tell the ending of a file

2008-01-08 Thread Christopher Cowart
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 [EMAIL PROTECTED], 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?  
 
 } 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 :)

Right. Here's another way using parameter expansion:

| if [ ${STRING##*.} = gz ] ; then
| echo true
| else
| echo false
| fi

The syntax is terse, but pretty popular in the /etc/rc family of scripts. 

-- 
Chris Cowart
Lead Systems Administrator
Network  Infrastructure Services, RSSP-IT
UC Berkeley


pgpWUJi3EfOiH.pgp
Description: PGP signature


Re: is there a /bin/sh method to tell the ending of a file

2008-01-07 Thread Paul Procacci
Is this what you mean?

-
#!/bin/sh

STRING=mystring.gz

if [ .gz = `echo \$STRING\ | sed -n 's/.*\(\.gz\)$/\1/p'` ]; then
 echo test;
fi

---

~Paul

On Mon, Jan 07, 2008 at 09:10:58PM -0800, Gary Kline wrote:
 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.
 
 tiam
 
 gary
 
 
 
 -- 
 Gary Kline  Seattle BSD Users' Group (seabug)  | [EMAIL PROTECTED]
 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
 
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: is there a /bin/sh method to tell the ending of a file

2008-01-07 Thread Bill Campbell
On Mon, Jan 07, 2008, Paul Procacci wrote:
Is this what you mean?

-
#!/bin/sh

STRING=mystring.gz

if [ .gz = `echo \$STRING\ | sed -n 's/.*\(\.gz\)$/\1/p'` ]; then
 echo test;
fi

Another way might be

#!/bin/sh

# basename $filename .gz returns $filename unless it has a .gz
# suffix.
[ `basename $filename .gz` = $filename ] || {
echo $filename has a .gz suffix
}

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

Intellectually, teachers fall between education theorists and bright
cocker spaniels. (Probably closer to the education theorists. The AKC has
been doing wonders with spaniels.) If you think I'm kidding look at the
GREs for education majors, whose scores are the lowest of all fields, and
remember that these are the smart ones. -- http://www.FredOnEverything.net
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: is there a /bin/sh method to tell the ending of a file

2008-01-07 Thread Paul Procacci
/Gulp

Guess I'm too `new` skool!  ;-P

Cheers!

On Tue, Jan 08, 2008 at 12:47:53AM -0500, John Levine wrote:
 -
 #!/bin/sh
 
 if [ .gz = `echo \$STRING\ | sed -n 's/.*\(\.gz\)$/\1/p'` ]; then
  echo test;
 fi
 
 E.  I think that we can now safely take advantage of
 features added to the shell in the late 1970s.
 
 ---
 #!/bin/sh
 
 case $1 in
  *.gz) echo that is a gzipped file ;;
  *) echo that is not a gzipped file ;;
 esac
 
 ---
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: is there a /bin/sh method to tell the ending of a file

2008-01-07 Thread Jon Hamilton
} On Mon, Jan 07, 2008 at 09:10:58PM -0800, Gary Kline wrote:
} Paul Procacci [EMAIL PROTECTED], 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 
   [EMAIL PROTECTED]
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: is there a /bin/sh method to tell the ending of a file

2008-01-07 Thread John Levine
-
#!/bin/sh

if [ .gz = `echo \$STRING\ | sed -n 's/.*\(\.gz\)$/\1/p'` ]; then
 echo test;
fi

E.  I think that we can now safely take advantage of
features added to the shell in the late 1970s.

---
#!/bin/sh

case $1 in
 *.gz) echo that is a gzipped file ;;
 *) echo that is not a gzipped file ;;
esac

---
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: is there a /bin/sh method to tell the ending of a file

2008-01-07 Thread Gary Kline
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 [EMAIL PROTECTED], 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 
[EMAIL PROTECTED]

-- 
Gary Kline  Seattle BSD Users' Group (seabug)  | [EMAIL PROTECTED]
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

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: is there a /bin/sh method to tell the ending of a file

2008-01-07 Thread Gary Kline
On Mon, Jan 07, 2008 at 11:34:08PM -0600, Paul Procacci wrote:
 Is this what you mean?
 
 -
 #!/bin/sh
 
 STRING=mystring.gz
 
 if [ .gz = `echo \$STRING\ | sed -n 's/.*\(\.gz\)$/\1/p'` ]; then
  echo test;
 fi
 
 ---
 
 ~Paul
 

Sorry.  You get the credit for the predicate expression; Jon had the 
simpler 
(and more readable:) one.But yours is warm+fuzzy in it's cleverness
:-)

gary



-- 
Gary Kline  Seattle BSD Users' Group (seabug)  | [EMAIL PROTECTED]
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

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]