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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 12 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
12 comments… add one
  • irado Sep 23, 2008 @ 11:12

    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 –.

  • henry Sep 23, 2008 @ 13:31


    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.

  • marco Sep 23, 2008 @ 13:57

    > henry ‘any possible book i could study more on shell programming?’:
    Richard Stones, Neil Matthew – Beginning Linux Programming
    ISBN-13: 9780764543739

  • Johan Sep 23, 2008 @ 14:38

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

  • 🐧 nixCraft Sep 23, 2008 @ 15:14

    Mastering UNIX Shell Scripting: Books by Randal K. Michael

    Oreilly Classic Shell Scripting

  • dj Sep 25, 2008 @ 17:09

    Henry, try “Linux Command” site at:
    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:

  • marco Sep 25, 2008 @ 18:26

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

    • cucho Dec 16, 2012 @ 16:01

      This page is * DEAD * Does not exist anymore.

  • tom Nov 6, 2009 @ 8:38

    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………..
    thank you

  • runner724 Dec 9, 2009 @ 16:53

    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

  • Anonymous Jun 15, 2010 @ 22:57

    rsync -avz –delete –numeric-ids \
    –exclude=”.Trash” \
    –exclude=”Downloads” \
    $HOME $SERVERIP:backups/user/ 1>$LOGFILE

    what does this mean?

  • 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.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum