I did not understand what is ${0##/}
PGM=${0##/}
TMP=/tmp/${PGM}.$$
Please explain me.
I did not understand what is ${0##/}
PGM=${0##/}
TMP=/tmp/${PGM}.$$
Please explain me.
'man ksh' yields the following:
${name#pattern}, ${name##pattern}
If pattern matches the beginning of the value of parameter name,
the matched text is deleted from the result of substitution. A
single # results in the shortest match, two #'s results in the
longest match.
${name%pattern}, ${name%%pattern}
Like ${..#..} substitution, but it deletes from the end of the
value.
PGM=${0##/}
TMP=/tmp/${PGM}.$$
$0 is the complete-name-of-the-script in side the script (e.g. /home/mydir/myscript.sh)
So, ${0##/} means the complete-name-of-the-script without the starting-slash (if it exists)!!
But, what I thing you wanted to write is:
PGM=${0##*/}
which means complete-name-of-the-script without everthing up to and including the last-slash (e.g. myscript.sh)
Then, $$ is the Process-ID of the current script. So, TMP will be set to be /tmp/myscript.sh.1234 (where 1234 is the process-id).
This combination is normally used to create unique (i.e. different for each running script) names.