Results 1 to 3 of 3
I'm new to bash scripting. I been using a nifty tool to get the basename and extention for a filename.
Example:
file=blarg.txt
echo ${file%.*}
> blarg
echo ${file##*.}
> txt
...
- 05-26-2010 #1Just Joined!
- Join Date
- Dec 2008
- Location
- New Hampshire
- Posts
- 4
${file##*.} and ${file%.*} explanation?
I'm new to bash scripting. I been using a nifty tool to get the basename and extention for a filename.
Example:
file=blarg.txt
echo ${file%.*}
> blarg
echo ${file##*.}
> txt
And of course I can replace the "." for any character or string. This is great for paths too.
However, I don't really understand the syntax as it is cryptic. And when my friends ask for an explanation, I just
. Does anyone know what's going on with the ##* and %.*? Is there a terminology I can use to google a tutorial or more tools.
Thanks a head of time!
~Kat
- 05-27-2010 #2Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
It's about bash parameter expansion, it's built-in.
Search for 'Remove matching prefix pattern' and 'Remove matching suffix pattern'
There are many more parameter expansion.
man bash0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 05-27-2010 #3
Here's a good description of it: parameter substitution
Can't tell an OS by it's GUI


Reply With Quote