This code is from apache2 service starting script.
What does it mean?
SCRIPTNAME="${0##*/}"
It finds the name of the script being run, stripping out its directory. For instance if the script is /etc/init.d/httpd
then this would set SCRIPTNAME=httpd
.
$0
, or ${0}
, is the name of the script being executed. The ##
operator is used to remove any leading string that matches the pattern */
. *
is a wildcard character so */
means "any string followed by a forward slash".
The effect of this is to remove any leading directory names from $0
, leaving just the name of the script.
From man bash:
${parameter#word}
${parameter##word}The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the beginning of the 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With