-   Linux - Newbie (
-   -   first line in shell scripting (

fernfrancis 02-15-2011 06:20 AM

first line in shell scripting
hi guys

I am a bit confused with the first line while writing a shell script , if someone can please explain me the meaning of the first line
" #!/bin/bash "

the confusion for me is the # at the beginning , in shell scripting # means a comment. but in this case it loads the shell which the script must use,instead of commenting the line how is this possible. where is this defined , any particular file.

so if someone can throw some light on this

EricTRA 02-15-2011 06:35 AM


Some clarifications on the 'shebang' or also called 'hashbang':
and a lot more to be found at Google.

Kind regards,


citi 02-15-2011 09:50 AM

the way i understand it is it identifies the file as a bash script and in my experience with editors like nano and vi the commented lines are preceded with two #. it is in python i notice one # marks a comment.

EricTRA 02-15-2011 09:53 AM

Hi citi,

In Bash it also considers only 1 # as a comment, if you want to put two no problem but one suffices. The only difference with the 'shebang' is that it must be the first two characters in a file. If the first character is a # directly followed by ! then it gets interpreted as 'shebang' or 'hashbang' and the command following it will be used to process the file (bash, sh, perl, python, ...).

Kind regards,


All times are GMT -5. The time now is 06:22 PM.