What is the function of bash shebang?What is the difference between executing a file using ./file or sh file?How does bash understand it?
What is the function of bash shebang?
bash;shell script;shell;scripting
The function of shebang is:Interpreter directives allow scripts and data files to be used as  commands, hiding the details of their implementation from users and  other programs, by removing the need to prefix scripts with their  interpreter on the command line.What is the different between executing a file using ./file or sh file? A Bourne shell script that is identified by the path some/path/to/foo,  has the initial line,    #!/bin/sh -xand is executed with parameters bar and baz as    some/path/to/foo bar bazprovides a similar result as having actually executed the following command line instead:    /bin/sh -x some/path/to/foo bar bazNote: On 1980 Dennis Ritchie introduced  kernel support for interpreter directives:The system has been changed so that if a file being executedbegins with the magic characters #! , the rest of the line is understoodto be the name of an interpreter for the executed file.Previously (and in fact still) the shell did much of this job;it automatically executed itself on a text file with executable modewhen the text file's name was typed as a command.Putting the facility into the system gives the followingbenefits.1) It makes shell scripts more like real executable files,because they can be the subject of 'exec.'2) If you do a 'ps' while such a command is running, its realname appears instead of 'sh'.Likewise, accounting is done on the basis of the real name.3) Shell scripts can be set-user-ID.Note: Linux ignores the setuid bit on all interpreted executables (i.e. executables starting with a #! line).4) It is simpler to have alternate shells available;e.g. if you like the Berkeley csh there is no question aboutwhich shell is to interpret a file.5) It will allow other interpreters to fit in more smoothly.More info : Wikipedia Shebang The #! magic, details about the shebang/hash-bang