Skip to content
The Bash Insectarium

/static/insetario/en/inseto/param-sufixo/

Menu

BSH-010 · Parameters

${var%sufixo}

It gnaws at the end of the value: % takes the smallest bite, %% the largest.

The mirror of #, aimed at the end: % removes the shortest match from the end, %% the longest. Reading % as "trim the tail" undoes the confusion with its sibling.

Two classics: ${arquivo%.*} drops the extension, ${caminho%/*} drops the name and the directory remains — dirname without a subshell.

$ arquivo=larvas.tar.gz
$ echo ${arquivo%.gz}
larvas.tar
$ echo ${arquivo%%.*}
larvas
The short bite takes one suffix; the long one, all of them.