Example: I want to create a quick command to shrink images (for my filebrowser)....FN=/tmp/some-image.jpggm convert $FN -resize 50% $(dirname $FN)/$(basename $FN .jpg/png/gif).jpg...How can I specify that more than one suffix should be stripped?
Remove multiple possible suffixes
shell;basename
basename only takes one suffix to remove, and gives the base name (removes the directory components) which you don't want there anyway, so basename is not really the right tool for your need.The traditional tool to extract data  from a string is expr:FN_without_extension=$(expr x$FN : 'x\(.*\)\.')But modern shells (like zsh, bash, ksh, ash, yash, all POSIX compliant sh...) have builtin operators for that, so you hardly ever need expr nowadays (and it's best avoided as it's got a few issues).${var%pattern}removes the (smallest) part matching pattern from the end of $vargm convert $FN -resize 50% ${FN%.*}.jpgShells like tcsh or zsh have operators to remove extensions. Zsh:gm convert $FN -resize 50% $FN:r.jpg(r for rootname).If you want to remove the extension, only if it's one of jpg/png/gif, then that becomes more complicated and shell dependant.With zsh:gm convert $FN -resize 50% ${FN%.(jpg|png|gif)}.jpgWith ksh:gm convert $FN -resize 50% ${FN%.@(jpg|png|gif)}.jpgWith bash:shopt -s extglobgm convert $FN -resize 50% ${FN%.@(jpg|png|gif)}.jpgWith expr:gm convert $FN -resize 50% $(  expr \( x$FN : '\(.*\)\.png$' \| \          x$FN : '\(.*\)\.jpg$' \| \          x$FN : '\(.*\)\.gif$' \| x$FN \) : 'x\(.*\)').jpg(yes, that's convoluted, and that's to work around some of the issues of expr).With some expr implementations, it can be simplified to:expr \( x$FN : '\(.*\)\.\(png\|jpg\|gif\)$' \| x$FN \) : 'x\(.*\)'You could also use sed:FN_without_ext=$(printf '%s\n' $FN |  sed -e '$!b' -e 's/\.png$//;t' -e 's/\.gif$//;t' -e 's/\.jpg$//')If you want it case insensitive, you can replace the png/gif/jpg in all those solutions above with [pP][nN][gG]..., some shells/tools can also do case insensitive matching:zsh: setopt extendedglob FN_without_ext=${FN%.(#i)(gif|png|jpg)}ksh93: FN_without_ext=${FN%.~(i:gif|png|jpg)}bash: shopt -s nocasematch LC_ALL=C if [[ $FN =~ (.*)\.(gif|png|jpg)$ ]]; then   FN_without_ext=${BASH_REMATCH[1]} else   FN_without_ext=$FN fiGNU sed: FN_without_ext=$(printf '%s\n' $FN | sed -r '$s/\.(png|gif|jpg)$//I')