[lang-ref] ( get_stem ) ( bash )
@test "get stem" {
# ${fname%%.*}
# Note: %.* (shortest match) is closer to other languages' standard libraries: it removes only the last extension.
# Dot-prefixed names (dotfiles) are intentionally ignored here.
# shortest match (remove last suffix)
fname="file1.txt" ; [ "${fname%.*}" = "file1" ]
fname="file1.tar.gz" ; [ "${fname%.*}" = "file1.tar" ]
fname="/path/to/file1.txt" ; [ "${fname%.*}" = "/path/to/file1" ]
fname=".bashrc" ; [ "${fname%.*}" = "" ]
# longest match (remove all suffixes)
fname="file1.txt" ; [ "${fname%%.*}" = "file1" ]
fname="file1.tar.gz" ; [ "${fname%%.*}" = "file1" ] # difference
fname="/path/to/file1.txt" ; [ "${fname%%.*}" = "/path/to/file1" ]
fname=".bashrc" ; [ "${fname%%.*}" = "" ]
# longest match causes another issue
fname="/path/to/01.sample/file1.txt" ; [ "${fname%%.*}" = "/path/to/01" ]
}