[Bash] Remove the last extension from a filename

Created on November 30, 2026

Use parameter expansion with %.* to strip the shortest suffix beginning with a dot.

filename="archive.tar.gz"
echo "${filename%.*}"
archive.tar

For archive.tar.gz, this removes only .gz. A filename without a dot stays the same.

filename="README"
echo "${filename%.*}"
README
Bash