Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 17, 2008, 04:58 PM   #1
msb65
macrumors member
 
Join Date: Sep 2008
Bash on Leopard

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
msb65 is offline   0 Reply With Quote
Old Sep 17, 2008, 05:16 PM   #2
idelovski
macrumors regular
 
Join Date: Sep 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.
idelovski is offline   0 Reply With Quote
Old Sep 18, 2008, 02:53 AM   #3
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: 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
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Sep 18, 2008, 03:08 PM   #4
MacUser2525
macrumors 65816
 
Join Date: Mar 2007
Location: Canada
Quote:
Originally Posted by msb65 View Post
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.
Quote:
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=PO...UTF-8&oe=UTF-8
Quote:
My question is, is there difference on a Mac OS between using #!/bin/bash or #!/bin/sh?
Yes they are two different shells.
Quote:
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.
Quote:
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...rch&lr=lang_en
Quote:
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.
MacUser2525 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
changed bash to tcsh in gui MAC OS 10.5.8 how to chage back to bash? Mac10.5.8USER OS X 0 Feb 3, 2014 04:45 PM
need help on bash scripting tonkpils Mac Programming 6 Dec 10, 2013 07:37 AM
getStartupVolumeName() in bash? zeppenwolf Mac Programming 6 Nov 4, 2013 11:43 PM
RE: bash and history... switon OS X 0 Jan 4, 2013 10:57 AM
Piping in bash Lingonsylt OS X 7 Dec 6, 2012 07:28 PM

Forum Jump

All times are GMT -5. The time now is 03:26 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC