What is 1st line(#!/bin/sh) in shell script?Expalin deeply?what is the this line role in shell script?


#1

Hi Guys,

Hope all are doing good.

Can you any one explain above questions deeply.

What is 1st line(#!/bin/sh) in shell script?Explain deeply?what is the this line role in shell script?

with out #!/bin/sh we can execute shell shell script? if yes what is the need of of 1st line?If no why we need to use

Please explain


#2

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.