I'm looking at some old unix code and, need some help figuring out some of the commands. Here is the line that I'm having trouble with:
echo "$(date) ${0##*/} started" >> $summary.log
I know the first statement prints out the date but, I don't understand the second command on the line ${0##/} - what is this doing? I know $0 is the script name but, I don't know what the rest of the command should print out. I know this is very old code -- does anyone know what the command ${0##/} is supposed to echo out?
Try the man pages. Here is what man sh (Section: Parameter Expansion)had to say
${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 expan-
sion 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.
In your case, $0 would translate to the current shell's path. Like /bin/bash or /bin/ksh or /usr/bin/sh or whichever it is.