prefix and suffix removal

The ${name#pattern} and ${name%pattern} forms, which remove a matching glob pattern from the start or the end of a value.

In more detail

One # or % removes the shortest match and a doubled ## or %% the longest. The patterns are globs, not regular expressions. ${file%.txt} strips an extension and ${path##*/} keeps only the last part of a path, with no extra process.

Example

file=report.txt; echo "${file%.txt}"

Related terms

Taught in

References