As explained, when you execute a script, the shebang tells the system which program to interpret it with. If the line is
/bin/bash, then it will be processed by bash, and if it has
/bin/awk, or
/bin/perl, or
/bin/python, it will be processed by those programs.
Note that this only applies when you execute the script directly. If you instead manually feed the script into an interpreter, the leading # generally means it will be ignored as a comment (depending on how the interpreter is designed).
Code:
$ ./myscript #executes the interpreter in the shebang to process the script.
$ bash <./myscript #executes bash first, and feeds it the script to interpret.
#the shebang is ignored.
In addition, note that
#!/bin/sh is a bit special. When it's used as the shebang, the script is treated as a
posix-compliant script, regardless of the actual interpreter used. That is, your system could be set up to use
bash as the default interpreter, or
dash, or
ksh, or one of several other shells that offer posix support, but if your script starts with
/bin/sh, they will all treat it identically, as long as it contains only syntax defined by the posix standard.
This means that if you want to use all of the advanced features offered specifically by
bash (e.g. arrays or extended globbing), be sure to use
#!/bin/bash, and NOT
#!/bin/sh as your first line.