[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell script question

Carlos Sousa <csousa@tvtel.pt> writes:

> On Mon, 13 Oct 2003 08:30:23 +0100 Colin Watson wrote:
>> Here's a little expression that strips off any trailing ".<extension>"
>> from $1 and tacks on ".wav".
>>   "${1%.*}.wav"
> That's much better, no dependency on yet another utility, so more portable
> code.

Not really; as was noted, the expression is bash-specific, and lots of
non-Linux Unices don't have bash.  So while it's more verbose, every
/bin/sh on pretty much any sane system will be able to run

  `echo "$1" | sed -e 's/\\.[^.]*//'`

(Provided, of course, that you can read the sed expression, which is
          s/        \\.             [^.]*              /          /
 search-and-replace ".", then any number of not-dots, with nothing.)

David Maze         dmaze@debian.org      http://people.debian.org/~dmaze/
"Theoretical politics is interesting.  Politicking should be illegal."
	-- Abra Mitchell

Reply to: