Explain: #!/bin/bash - or #!/bin/bash -- In A Shell Script

by on September 23, 2008 · 12 comments· LAST UPDATED September 23, 2008

in , ,

Q. I know #!/bin/bash is shebang line. But, I noticed a few shell script shebang line ends with a single dash ( #!/bin/bash - ) or double dash ( #!/bin/bash -- ). Can you explains me purpose of such shebang line?

A. A - or -- signals the end of options and disables further option processing i.e. bash will not accept any of its option. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --. This is done to improve script security. Some user may perform setuid based script root spoofing. To avoid interpreter spoofing you need to add -- to #!/bin/bash. This is rare but possible attack.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 12 comments… read them below or add one }

1 irado September 23, 2008 at 11:12 am

man bash:

” — A — signals the end of options and disables further option processing. Any argu ments after the — are treated as filenames and arguments. An argument of – is equivalent to –.

Reply

2 henry September 23, 2008 at 1:31 pm

Hello,

Please, any possible book i could study more on shell programming? Please, this is the second mail i am sending and i haven’t got a reply.

Reply

3 marco September 23, 2008 at 1:57 pm

> henry ‘any possible book i could study more on shell programming?':
Richard Stones, Neil Matthew – Beginning Linux Programming
ISBN-13: 9780764543739
12,20$
http://www.amazon.com/gp/product/0764543733

Reply

4 Johan September 23, 2008 at 2:38 pm

“Advanced Bash-Scripting Guide” is a great book available at the Linux Documentation Project’s website – http://tldp.org/guides.html

Reply

5 nixCraft September 23, 2008 at 3:14 pm

Mastering UNIX Shell Scripting: Books by Randal K. Michael

Oreilly Classic Shell Scripting

Reply

6 dj September 25, 2008 at 5:09 pm

Henry, try “Linux Command” site at:
http://www.linuxcommand.org/
The author is in process of writing a book, but imho, if the goal is to teach bash, the site gets an A+. He walks through a real example. It’s good clean code. You’ll learn to do it right.

Then I would look at “The Linux Documentation Project” at:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

Reply

7 marco September 25, 2008 at 6:26 pm

> DJ “http://www.linuxcommand.org/”
That seems to be a real good source. :)

Reply

8 cucho December 16, 2012 at 4:01 pm

This page is * DEAD * Does not exist anymore.

Reply

9 tom November 6, 2009 at 8:38 am

when i loggin into redhat as an user . i got a prompt like this -bash-3.1$
how i can change that into normal user prompt………..
pls
thank you

Reply

10 runner724 December 9, 2009 at 4:53 pm

you can set whatever prompt you like with

set PS1=”[newprompt]”; export PS1

but you’ll have to set the prompt every time you log in, unless you can edit the hidden bash profile that should be in your home dir

Reply

11 Anonymous June 15, 2010 at 10:57 pm

#!/bin/bash
SERVERIP=192.168.23.18
LOGFILE=/home/user/backup.log
rsync -avz –delete –numeric-ids \
–exclude=”.Trash” \
–exclude=”Downloads” \
$HOME $SERVERIP:backups/user/ 1>$LOGFILE

what does this mean?

Reply

12 Fred October 20, 2010 at 3:31 pm

Do none of these people know how to use Google ffs?

Reply

Leave a Comment

Tagged as: , , , , , , ,

Previous Faq:

Next Faq: