Typically, a shell script is started by your default shell defined in the / etc / passwd file. But you can explicitly define a program that can run your script.
Unices uses a generic method to determine which program should run for a particular script (man execve (2) ). If the script has the correct execution rights, and in the script the first line begins with the characters #! , it will be launched by the program defined subsequently.
For example, if the first line is #!/usr/bin/awk -f , the rest of the file will be passed to awk (so it should use awk syntax). Or, if the Makefile starts with #!/usr/bin/make -f , the rest of the file will be passed to make . You can run the script as a regular program, and the script can be written in awk or make syntax (or any other).
If execve does not find #! as the first two characters of the file, it will be considered as a regular script file, and it will work as is.
So using #! You can define the script language, and you do not need to know which shell is being used by another user using your script. On any other line #! your default shell will be interpreted, which is usually a comment line.
Truey source share