Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>In bash script, what does #!/bin/bash at the 1st line mean ?</strong></p> <p>In Linux system, we have shell which interprets our UNIX commands. Now there are a number of shell in Unix system. Among them, there is a shell called bash which is very very common Linux and it has a long history. This is a by default shell in Linux.</p> <p>When you write a script (collection of unix commands and so on) you have a option to specify which shell it can be used. Generally you can specify which shell it wold be by using <a href="http://manpages.ubuntu.com/manpages/natty/man1/dash.1.html" rel="noreferrer">Shebang</a>(Yes that's what it's name). </p> <p>So if you #!/bin/bash in the top of your scripts then you are telling your system to use bash as a default shell.</p> <p><strong>Now coming to your second question :Is there a difference between #!/bin/bash and #!/bin/sh ?</strong></p> <p>The answer is Yes. When you tell #!/bin/bash then you are telling your environment/ os to use bash as a command interpreter. This is hard coded thing.</p> <p>Every system has its own shell which the system will use to execute its own system scripts. This system shell can be vary from OS to OS(most of the time it will be bash. Ubuntu recently using <a href="http://manpages.ubuntu.com/manpages/natty/man1/dash.1.html" rel="noreferrer">dash</a> as default system shell). When you specify #!/bin/sh then system will use it's internal system shell to interpreting your shell scripts.</p> <p>Visit this <a href="http://kaziprogrammingblog.osinweb.com/article/showarticle/How%20to%20reference%20your%20shell%20inside%20your%20script%20in%20Linux" rel="noreferrer">link</a> for further information where I have explained this topic. </p> <p>Hope this will eliminate your confusions...good luck.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload