I want to get the filename (without extension) and the extension separately.
The best solution I found so far is:
NAME=`echo \"$FILE\" | cut -d\'.\'
Mellen writes in a comment on a blog post:
Using Bash, there’s also ${file%.*} to get the filename without the extension and ${file##*.} to get the extension alone. That is,
${file%.*}
${file##*.}
file="thisfile.txt" echo "filename: ${file%.*}" echo "extension: ${file##*.}"
Outputs:
filename: thisfile extension: txt