What is the purpose of $0?

The purpose of $0 in Bash is to represent the name of the script being executed. It provides the full path or just the name of the script, depending on how the script was called. This can be useful for displaying the script name in messages, logging, or when you need to reference the script itself within the code.

For example, if you have a script named myscript.sh, using $0 inside that script will return myscript.sh or the full path to it, depending on how it was invoked.

0 Comments

no data
Be the first to share your comment!