Bash (Scripting) - scriptname $0
by
Jeremy Canfield |
Updated: June 26 2023
| Bash (Scripting) articles
$0 can be used to get the name of the Bash script being invoked. For example, let's say you have a Bash script named foo.sh. Here is how you would show that foo.sh is the name of the script.
#!/usr/bin/perl
echo scriptname = $0
Or, more commonly, scriptname is stored in a constant variable.
#!/usr/bin/perl
SCRIPTNAME=$0
echo scriptname = $SCRIPTNAME
Which should return the following.
scriptname = foo.sh
Did you find this article helpful?
If so, consider buying me a coffee over at