Get the Stem of a File Name in bash

April 2026
bash
#!/bin/bash

EXAMPLE_PATH="path/to/example-file.txt"

BASENAME=$(basename "$EXAMPLE_PATH")
STEM="${BASENAME%.*}"

echo $STEM
output
example-file