Artificial intelligent assistant

What does PROG=${0##*/} mean in a bash script? `PROG=${0##*/}` seems to parse out the shell script name, but it's unclear how that works. ${0} I understand is the first or 0th variable.

As tarabyte alludes to, this has to deal with parameter expansion.

$0 is the name and path that this script was executed with. For example, if you call /usr/bin/example.sh, then $0 will be "/usr/bin/example.sh". If your current working directory is /usr, and you call the same script with ./bin/example.sh, then $0 will be "./bin/example.sh".

As for the "#", this means to expand $0 after removing the previously specified prefix. In this case the previously specified prefix is the */ glob. A single "#" is non-greedy, so after it matches the first */ glob, it will stop. So it will remove the first "/" and everything before it. Two "#"'s mean to greedily remove all */. So it will find remove all "/" and everything that comes before them.

Edit Summary: ${0##*/} is equivalent to $(basename $0) but without the extra forking

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 35596812a4559450fdb22a8630c975f7