[username@notebook ~]$ cat foo.sh #!/bin/bashecho $0[username@notebook ~]$ ./foo.sh./foo.sh[username@notebook ~]$ Question: How can I output the foo.sh? No matter how was it executed. 
How to print out only the script name?
bash;shell script
Use basename:#!/bin/bashbasename -- $0If you want to assign it to a variable, you'd do:my_name=$(basename -- $0)