Bash on Leopard

Discussion in 'Mac Programming' started by msb65, Sep 17, 2008.

  1. macrumors member

    Joined:
    Sep 17, 2008
    Messages:
    61
    #1
    Hi,

    I am running Leopard on a Powerbook G4.

    I am writing a BASH shell script. My shebang is #!/bin/sh. As I understand it, in Mac OS #!/bin/sh actually points to bash (Please tell me if that isn't true). But I have read that when bash is invoked with #!/bin/sh it attempts to be POSIX compliant (not quite sure what that means).

    My question is, is there difference on a Mac OS between using #!/bin/bash or #!/bin/sh? If I were only to change my shebang to #!/bin/bash, would my script run exactly the some way? If not. what would be different. The reason I ask is that I am writing this script for someone who will run it using Ubuntu, and I want to emulate his system as best I can. Thanks!

    Mike
     
  2. macrumors regular

    Joined:
    Sep 11, 2008
    Messages:
    231
    #2
    On my system $ ls -l /bin/bash /bin/sh gives:

    -rwxr-xr-x 1 root wheel 1068844 Dec 13 2006 /bin/bash
    -r-xr-xr-x 1 root wheel 1068844 Dec 13 2006 /bin/sh


    So they are the same or very similar ;) Strangely, they have different permissions.
     
  3. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Messages:
    4,861
    Location:
    Western US
    #3
    A year and a half later, they're 36 bytes different...and still have different permissions:

    $ ls -l /bin/bash /bin/sh
    -rwxr-xr-x 1 root wheel 1244928 Mar 4 2008 /bin/bash
    -r-xr-xr-x 1 root wheel 1244960 Mar 4 2008 /bin/sh
     
  4. macrumors 65816

    Joined:
    Mar 17, 2007
    Messages:
    1,112
    Location:
    Canada
    #4
    As the others have shown with their listing it points to the sh shell not bash.
    You would be invoking the sh shell not bash and Google is your friend for the second part, basically my understanding of POSIX is that it is supposed to enable you to write once and expect the same result when run on any of the OS's that claim to be compliant.

    http://www.google.com/search?as_q=POSIX compliant&lr=lang_en&ie=UTF-8&oe=UTF-8
    Yes they are two different shells.
    Possibly but if you want the same behavior use the sh shell.
    Bashisms as Debian would call them if you included them in your script they can give unexpected results when invoked in a sh shell.

    http://www.google.com/search?hl=en&q=bashisms&btnG=Search&lr=lang_en
    Then the sh shell is what you want if it works on your system it should just work on his the same way.

    That said there is a good chance that bash would work the only difference I found when using the simple scripts I wrote on Debian in OS X was the output of the ls -l command. I had to make an adjustment in the -f number of the cut command I was using with it that is other than the obvious changing of the path names of course.
     

Share This Page