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

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.

Advertisement

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

12 comments… add one
  • Fred Oct 20, 2010 @ 15:31

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.