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.
Explain: #!/bin/bash - or #!/bin/bash -- In A Shell Script
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!
Previous post: How To Select Best Linux Desktop Application
Next post: Linux Error: Page Allocation Failure and Solution


{ 7 comments… read them below or add one }
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 –.
“
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.
> 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
“Advanced Bash-Scripting Guide” is a great book available at the Linux Documentation Project’s website - http://tldp.org/guides.html
Mastering UNIX Shell Scripting: Books by Randal K. Michael
Oreilly Classic Shell Scripting
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
> DJ “http://www.linuxcommand.org/”
That seems to be a real good source.