These things pops up from time to time, manipulating variables and strings using bash. There are a few very handy variable operators that can reliably detect whether strings are set or not, strip of tails or heads, and even do some basic replacements.