I never can remember this:

echo ${filename%.*}

will remove the trailing “.txt”. Mnemonic: % sorta looks like dividing two circles. “%.*” says to divide at the period, matching any file type.

I often use a for loop which looks something like:

for f in foo*.txt ; do
    echo ${f%.txt}

Keyword fodder: bash, shell script, remove file type, remove file extension, basename, base name, Linux, Unix