LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-15-2011, 05:20 AM   #1
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 224

Rep: Reputation: 18
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
 
Old 02-15-2011, 05:35 AM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello,

Some clarifications on the 'shebang' or also called 'hashbang':
http://wiki.linuxquestions.org/wiki/Shebang
http://en.wikipedia.org/wiki/Shebang_(Unix)
and a lot more to be found at Google.

Kind regards,

Eric
 
Old 02-15-2011, 08:50 AM   #3
citi
Member
 
Registered: Jan 2011
Location: Lithonia, GA
Distribution: Ubuntu,Fedora,puppy,CentOS
Posts: 36

Rep: Reputation: 6
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.
 
Old 02-15-2011, 08:53 AM   #4
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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,

Eric
 
  


Reply

Tags
shell script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell scripting: print first line and last line only Micro420 Programming 5 05-20-2007 06:26 PM
Shell scripting: How to add characters at the end of the line Micro420 Programming 7 05-18-2007 01:56 AM
Shell scripting :: comment N line in vi editor mahabooba Programming 4 07-28-2006 05:58 AM
command line options for firefox for shell scripting. dr_zayus69 Programming 1 05-25-2005 11:36 AM
line addressing with grep (shell scripting) j2dizzo Linux - General 13 03-03-2004 09:36 AM


All times are GMT -5. The time now is 03:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration