Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: What's the Difference Between #!/bin/bash and #/bin/bash ???

  1. #1
    Join Date
    Mar 2006
    Beans
    2,417

    What's the Difference Between #!/bin/bash and #/bin/bash ???

    does that exclamation point have to be there?

  2. #2
    Join Date
    Aug 2006
    Beans
    71

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    The # is just for commenting. When you add the ! you have a shebang line
    which generally means, that if the file is made into an executable,
    that line will be executed first.

  3. #3
    Join Date
    Mar 2005
    Location
    Brooklyn, NY
    Beans
    258
    Distro
    Gutsy Gibbon Testing

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    The ! is scarier But yeah what the dude above me said
    Since I get asked alot, I am originally from Ukraine but am Russian by nationality. My nick means specter in Russian.

  4. #4
    Join Date
    Mar 2006
    Beans
    2,417

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    Quote Originally Posted by iovar View Post
    The # is just for commenting. When you add the ! you have a shebang line
    which generally means, that if the file is made into an executable,
    that line will be executed first.
    so if you dont have the !, what happens?

  5. #5
    Join Date
    Mar 2005
    Location
    Ålsgårde, Denmark
    Beans
    939
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    Quote Originally Posted by erik1397 View Post
    so if you dont have the !, what happens?
    Nothing, it's just a comment.

  6. #6
    Join Date
    Feb 2006
    Beans
    1,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    Quote Originally Posted by mostwanted View Post
    Nothing, it's just a comment.
    No, it isn't. The system needs a shebang line (#!/bin/bash) in order to know how to run the file. Without it, it wouldn't know whether it's Perl, Python, or Awk. It doesn't work without the #, either. And not just because of Bash, either. The system needs the #.

    You don't need the shebang line if you run it as "bash myscript", but you need it if you want to just type "myscript".

    EDIT: I just did a rather cool demo of this. Make a file, and put this in it:
    Code:
    #!/usr/bin/gedit
    This file will open in gEdit.
    Make it executable (chmod +x filename) and run it (./filename). It will open in gEdit.
    Last edited by skymt; October 13th, 2006 at 10:08 PM.
    Are you Listening?
    Are you a Hero?
    Are you Sleeping?

  7. #7
    Join Date
    Mar 2005
    Location
    Ålsgårde, Denmark
    Beans
    939
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    Quote Originally Posted by skymt View Post
    No, it isn't. The system needs a shebang line (#!/bin/bash) in order to know how to run the file. Without it, it wouldn't know whether it's Perl, Python, or Awk. It doesn't work without the #, either. And not just because of Bash, either. The system needs the #.
    He was asking whether something would happen if the ! was missing to which I would replied "nothing happens" because then it would just be a comment and not an execution path. I don't really know where you're going at with this long reply...

  8. #8
    Join Date
    Mar 2006
    Beans
    2,417

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    i see...then how come aysiu's songbird script does not include it?

    http://www.psychocats.net/ubuntu/songbird

  9. #9
    Join Date
    Jan 2006
    Beans
    4,208
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    Hey that's a real good question! From what I thought I knew, that shouldn't work, unless one specifically runs
    sh songbird.sh
    but maybe someone can confirm if it runs as-is?

  10. #10
    Join Date
    Feb 2006
    Beans
    1,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: What's the Difference Between #!/bin/bash and #/bin/bash ???

    Quote Originally Posted by mostwanted View Post
    He was asking whether something would happen if the ! was missing to which I would replied "nothing happens" because then it would just be a comment and not an execution path. I don't really know where you're going at with this long reply...
    I misunderstood his post. I thought he was asking what would happen if you left out the whole ! line. I was trying to clarify. Sorry.

    But you have to admit, the gEdit thing is kind of cool.
    Are you Listening?
    Are you a Hero?
    Are you Sleeping?

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •