Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use/meaning of "#!/bin/sh" in shell scripting?

Tags:

shell

unix

What is the use/meaning of "#!/bin/sh" in shell scripting? Please let me know whether it is considered in the script or not as it is commented.

like image 646
Ravi Jain Avatar asked Jan 08 '12 11:01

Ravi Jain


People also ask

What is the meaning of what is the use?

—used to say that it would not be useful to do something "You should talk to her." "What's the use?

Whats the use of of?

Of is a preposition that indicates relationships between other words, such as belonging, things made of other things, things that contain other things, or a point of reckoning.

What's the use of examples?

Examples help you clarify complex concepts, even in regulations. They are an ideal way to help your readers. In spoken English, when you ask for clarification of something, people often respond by giving you an example. Good examples can substitute for long explanations.


2 Answers

The sha-bang ( #!) [1] at the head of a script tells your system that this file is a set of commands to be fed to the command interpreter indicated. The #! is actually a two-byte [2] magic number, a special marker that designates a file type, or in this case an executable shell script (type man magic for more details on this fascinating topic). Immediately 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. [3]

Source: http://tldp.org/LDP/abs/html/sha-bang.html#MAGNUMREF

like image 54
sisve Avatar answered Sep 17 '22 21:09

sisve


A script may specify #!/bin/bash on the first line, meaning that the script should always be run with bash, rather than another shell. /bin/sh is an executable representing the system shell. Actually, it is usually implemented as a symbolic link pointing to the executable for whichever shell is the system shell

like image 45
Raju Muke Avatar answered Sep 21 '22 21:09

Raju Muke