The art of String manipulation in bash: Substring Removal


#!/bin/bash

stringZ=abcABC123ABCabc
# |----| shortest
# |----------| longest

#Deletes shortest match of $substring from front of $string.
echo ${stringZ#a*C} # 123ABCabc
# Strip out shortest match between 'a' and 'C'.

# ##a*c: Deletes longest match of $substring from front of $string, from a to longest C
echo ${stringZ##a*C} # abc
# Strip out longest match between 'a' and 'C'.
#src: http://tldp.org/LDP/abs/html/string-manipulation.html

echo ============================

echo "LINKING WEB MODULES"
WEBDIR="/opt/SUNWappserver/domains/domain1/autodeploy"

ADDONS_DIR=/usr/local/my/addons
ADDONS=`ls $ADDONS_DIR/*.war 2>/dev/null`
echo "addons:$ADDONS"
#if [[ "$ADDONS_DIR" ]]; then
for WARFILE in $ADDONS; do
echo $WARFILE
echo ${WARFILE##*/}
rm -f $WEBDIR/${WARFILE##*/} &>/dev/null
ln -s $WARFILE $WEBDIR/${WARFILE##*/}
echo {WARFILE##*/}:${WARFILE##*/}
done