I launch script.sh and inside it i want to know what is his name
Is there a standard procedure to know the scripts name ? the idea is to be able to extract the name from teh full path + name contained in $0
Thanks
I launch script.sh and inside it i want to know what is his name
Is there a standard procedure to know the scripts name ? the idea is to be able to extract the name from teh full path + name contained in $0
Thanks
Yes, $0
will always contain the name of the script. Use basename to extract the name.
basename /some/really/long/dir/path/myscripts/coolscript.sh
will print coolscript.sh
So in your script, you could do this:
my_scriptname="$(basename $0)"
script="${0##*/}"
Edit:
This does the same thing as basename $0
. It strips off the last slash and everything before it from $0
using Bash's brace expansion.