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

Bill Campbell freebsd at celestial.com
Mon Jan 7 21:52:57 PST 2008


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:   bill at celestial.com  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


More information about the freebsd-questions mailing list