Bash on Leopard

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

  1. msb65 macrumors member

    Sep 17, 2008

    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!

  2. idelovski macrumors regular

    Sep 11, 2008
    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. HiRez macrumors 603


    Jan 6, 2004
    Western US
    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. MacUser2525 macrumors 68000


    Mar 17, 2007
    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. 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.
    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