I don't notice any difference when I call a script with say source
or ruby
. I'm guessing the benefit of a shebang line is that the environment knows what program to invoke if you're running the script as an executable. Not sure if this is the case; but I'm just verifying.
The source
command ignores the shebang line. When a script is invoked by shell in the normal way (not with .
or source
), shell uses the shebang line to fork the right interpreter for the script. The shebang line can contain:
#!/usr/local/bin/perl -w
)#!/usr/bin/env bash
). The advantage of this is that it prevents the hardcoded path and lets the shell pick up the environment specific path. In this case, there is no way to send an argument to the interpreterSee also: