Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

msb65

macrumors member
Original poster
Sep 17, 2008
61
0
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
 

idelovski

macrumors regular
Sep 11, 2008
235
0
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
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
 

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
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).

As the others have shown with their listing it points to the sh shell not bash.
But I have read that when bash is invoked with #!/bin/sh it attempts to be POSIX compliant (not quite sure what that means).

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
My question is, is there difference on a Mac OS between using #!/bin/bash or #!/bin/sh?

Yes they are two different shells.
If I were only to change my shebang to #!/bin/bash, would my script run exactly the some way?

Possibly but if you want the same behavior use the sh shell.
If not. what would be different.

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

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.