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

Posted on in Categories , , , , , , , last updated September 23, 2008

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.

12 comment

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

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

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

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

  5. #!/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?

Leave a Comment