I'm reading through the apache startup script trying to troubleshoot some problems with my server but at the very beginning there is a parameter expansion I don't really understand.
SCRIPTNAME="${0##*/}"
SCRIPTNAME="${SCRIPTNAME##[KS][0-9][0-9]}"
if [ -n "$APACHE_CONFDIR" ] ; then
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}"
else
DIR_SUFFIX=
fi
elif [ "${SCRIPTNAME##apache2-}" != "$SCRIPTNAME" ] ; then
DIR_SUFFIX="-${SCRIPTNAME##apache2-}"
APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX
else
DIR_SUFFIX=
APACHE_CONFDIR=/etc/apache2
fi
I'm just looking for some clarification on what ${parameter##word} construct does because the bash reference manual from gnu is not clear to me. The manual defines it like this...
${parameter#word} ${parameter##word}
the word is expanded to produce a pattern just as in filename expansion (see Filename Expansion). If the pattern matches the beginning of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ‘#’ case) or the longest matching pattern (the ‘##’ case) deleted. If parameter is ‘@’ or ‘*’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘*’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
does this mean that the first line stores an empty string back into SCRIPTNAME
or am I just way off base?
答案 0 :(得分:2)
The first line stores the basename
of the current file in SCRIPTNAME
. $0
is (generally) the name of the current script. See this Related question for discussion about it.
The second line then strips a prefix of K##
or S##
from the name (assuming /etc/init.d
link naming conventions.