Did you mean ##/*
, or ##*/
?
##/*
${0##/*}
is a bit unusual - it will strip off the prefix /...
from the start of $0
.
It's an all-or-nothing operation: If $0
starts with a slash (e.g. /home/bob/myscript.sh
), then it will strip everything and return an empty string. Otherwise (e.g. ./myscript.sh
) it will strip nothing and return the the whole of $0
.
(The double ##
indicates that it should strip the longest match; a single #
would only strip the first character, if it's a slash.)
I'm not sure how useful it is. Perhaps it could be used to help detect if a script is called from an absolute path or not.
##*/
${0##*/}
is more common - it will will strip off the prefix .../
from the
start of $0
.
e.g. if $0
is /home/bob/myscript.sh
, it will return myscript.sh
.
The ##
again indicates that it should strip the longest match, so it will strip all slashes (.../.../
).
(As opposed to a #
, which will strip the first slash only, e.g. /home/bob/myscript.sh
-> home/bob/myscript.sh
, a/b/myscript.sh
-> b/myscript.sh
)
sh
as well asbash
. See the Parameter Expansion section of the POSIX Shell Command Language document. Also see Removing part of a string (BashFAQ/100 (How do I do string manipulation in bash?)).