When the script contains shebang and is executed, saying:
./path/to/script
the program loader is prompted to run the path specified on the shebang line, specifying the path to the script as an argument.
In your case, the script contains #!/bin/rm as the first line and executes it by saying
./selfdeletingscript.sh
will result in the following:
/bin/rm ./selfdeletingscript.sh
In addition, you may notice that the execution of your script:
/bin/sh ./selfdeletingscript.sh
or
bash ./selfdeletingscript.sh
will not delete it because you specified the path to the interpreter.
source share