The
sha-bang ( #!) at the head of a script tells the system that this file is a set of commands to be fed to the command interpreter defined by the path-name. The #! is a two-byte magic number, a special marker that defines a file type.
Closely following the sha-bang is a path name - this is the path to the program that interprets the commands in the script, whether it be a shell, a programming language, or a utility. This command interpreter then executes the commands in the script, starting at the top (the line following the sha-bang line), and ignoring comments.
You can only leave out of #!, if the script consists only of a set of standard system commands, using no internal shell directives or builtins/functions.