[ale] stripping filename extension in bash
Geoffrey
esoteric at 3times25.net
Sun Dec 1 20:44:48 EST 2002
Christopher Bergeron wrote:
> Sweet! Thanks for all the help! I used the first suggestion (thanks
> Jason!) in my script, but I learned all about basename which is an
> extremely useful utility.
Better late then never.... I think you will find Dave Jackson's
suggestion to be the fastest, since it is a builtin.
foo=foo.com.bar
echo ${foo%.*}
This will strip anything from the LAST '.' to the end of the file name,
so it handles such things as the example above.
>
> Thanks again guys!!!
>
> -CB
>
>
> Danny Cox wrote:
>
>> Chris,
>>
>> On Sat, 2002-11-30 at 15:45, Christopher Bergeron wrote:
>>
>>
>>> Does anyone know how I can strip the extension from a filename in a
>>> bash script?
>>>
>>>
>>
>>
>> The "traditional" way is to use 'basename'. It will also remove any
>> preceding directory names. But, if you include an extension to strip,
>> it'll remove that too:
>>
>> I=xyzzy.jpg
>> echo $(basename "$I" .jpg)
>>
>> will echo "xyzzy".
>>
>> Of course, there are many ways to do what you want, as witnessed
>> by the
>> other suggestions.
>>
>>
>>
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>
>
--
Until later: Geoffrey esoteric at 3times25.net
I didn't have to buy my radio from a specific company to listen
to FM, why doesn't that apply to the Internet (anymore...)?
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list