How to get it's own file name within the same shell script?

Hello all,

This may be a silly question, but, let me ask... I searched the knowledge base, but couldn't get any help...

My script creates a log file. I need to name log file as whatever the script name with a ".log" extension.

Example: For the script name "start_cmd.sh", the log file should be named "start_cmd.sh.log" in the same script directory.

How do I get the script file name within the shell script?

Thanks.

It should be in $0. (that is dollar zero)

Thanks for the help Perderabo.

To be sure that you only get the script name, try using:

basename $0

Like so:

LogFile="$(basename $0).log"

This solves the issue of calling the script with a path name attached to the front.