A section of the bash man page called Variable Replacement describes the use of ${var#pattern} , ${var##pattern} , ${var%pattern} and ${var%%pattern} .
Assuming you have a variable named filename , for example,
filename="artifact-1.2.3.zip"
then the following are deducted based on the patterns:
% echo "${filename%-*}" artifact % echo "${filename##*-}" 1.2.3.zip
Why did I use ## instead of # ?
If the file name may contain a dash inside, for example:
filename="multiple-part-name-1.2.3.zip"
then compare the following two substitutions:
% echo "${filename#*-}" part-name-1.2.3.zip % echo "${filename##*-}" 1.2.3.zip
Once you have extracted the version and extension to isolate the version, use:
% verext="${filename##*-}" % ver="${verext%.*}" % ext="${verext##*.}" % echo $ver 1.2.3 % echo $ext zip
source share