#! /bin/sh prefix= suffix= commit=4bf28205 [ -n "$suffix" ] || suffix=$2 while [ "$suffix" != "${suffix#[^0-9]*.}" ]; do suffix=${suffix#[^0-9]*.} done echo $prefix$suffix${commit:+_}$commit