Re: Portability of shell scripts from other *nixes

2012-01-26 Thread Jerry
On Wed, 25 Jan 2012 16:08:07 -0600
Doug Poland articulated:

 Hello,
 
 I'm trying port some shell scripts to FreeBSD that were originally
 written on Darwin (OS X).
 
 The issue I'm having is the shebang line of the scripts in OS X is
 #!/bin/sh, and it turns out that is really an instance of bash, and
 the code contains some bashisms.  On FreeBSD I have bash in
 /usr/local/bin/bash.
 
 Is there an easy/best way to have a single shebang that works on
 both OS's?  I'd rather not change FreeBSD's bourne shell to bash with
 any symlinking of /usr/local/bin/bash to /bin/sh.

I have written several scripts for use on different OSs, all written in
Bash since that is my preferred scripting language, and have used this
as the shebang quite effectively:

#!/usr/bin/env bash

By the way, what version of Bash? If it is v4.x there are many
improvements that do not work on older v3.x and v2.x versions. 

-- 
Jerry ♔

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the Reply-To header.
__
Religion is the anthropomorphization of reality, that behind it all
there's an invisible man pulling invisible strings
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread Da Rock

On 01/26/12 08:08, Doug Poland wrote:

Hello,

I'm trying port some shell scripts to FreeBSD that were originally
written on Darwin (OS X).

The issue I'm having is the shebang line of the scripts in OS X is
#!/bin/sh, and it turns out that is really an instance of bash, and
the code contains some bashisms.  On FreeBSD I have bash in
/usr/local/bin/bash.

Is there an easy/best way to have a single shebang that works on
both OS's?  I'd rather not change FreeBSD's bourne shell to bash with
any symlinking of /usr/local/bin/bash to /bin/sh.

Cant you simply change the shebang to !#/usr/local/bin/bash?
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread Chuck Swiger
On Jan 25, 2012, at 2:08 PM, Doug Poland wrote:
 The issue I'm having is the shebang line of the scripts in OS X is
 #!/bin/sh, and it turns out that is really an instance of bash, and
 the code contains some bashisms.  On FreeBSD I have bash in
 /usr/local/bin/bash.
 
 Is there an easy/best way to have a single shebang that works on
 both OS's?  I'd rather not change FreeBSD's bourne shell to bash with
 any symlinking of /usr/local/bin/bash to /bin/sh.

Try using something like:

  #!/usr/bin/env bash

(If the shell scripts are something written by Apple rather than by 
third-parties, please also consider filing a bug report.)

Regards,
-- 
-Chuck

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread Warren Block

On Wed, 25 Jan 2012, Doug Poland wrote:


I'm trying port some shell scripts to FreeBSD that were originally
written on Darwin (OS X).

The issue I'm having is the shebang line of the scripts in OS X is
#!/bin/sh, and it turns out that is really an instance of bash, and
the code contains some bashisms.  On FreeBSD I have bash in
/usr/local/bin/bash.

Is there an easy/best way to have a single shebang that works on
both OS's?  I'd rather not change FreeBSD's bourne shell to bash with
any symlinking of /usr/local/bin/bash to /bin/sh.


Turns out that causes mysterious problems:
http://forums.freebsd.org/showthread.php?t=29088
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread Doug Poland

On Jan 25, 2012, at 18:04 , Chuck Swiger wrote:

 On Jan 25, 2012, at 2:08 PM, Doug Poland wrote:
 The issue I'm having is the shebang line of the scripts in OS X is
 #!/bin/sh, and it turns out that is really an instance of bash, and
 the code contains some bashisms.  On FreeBSD I have bash in
 /usr/local/bin/bash.
 
 Is there an easy/best way to have a single shebang that works on
 both OS's?  I'd rather not change FreeBSD's bourne shell to bash with
 any symlinking of /usr/local/bin/bash to /bin/sh.
 
 Try using something like:
 
  #!/usr/bin/env bash
 
 (If the shell scripts are something written by Apple rather than by 
 third-parties, please also consider filing a bug report.)
 
This gets me closer, but the scripts behave differently now on OS X.  For 
example, printf's don't output the same.  

-- 
Regards,
Doug



___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread Da Rock

On 01/26/12 12:55, Doug Poland wrote:

On Jan 25, 2012, at 18:04 , Chuck Swiger wrote:


On Jan 25, 2012, at 2:08 PM, Doug Poland wrote:

The issue I'm having is the shebang line of the scripts in OS X is
#!/bin/sh, and it turns out that is really an instance of bash, and
the code contains some bashisms.  On FreeBSD I have bash in
/usr/local/bin/bash.

Is there an easy/best way to have a single shebang that works on
both OS's?  I'd rather not change FreeBSD's bourne shell to bash with
any symlinking of /usr/local/bin/bash to /bin/sh.

Try using something like:

  #!/usr/bin/env bash

(If the shell scripts are something written by Apple rather than by 
third-parties, please also consider filing a bug report.)


This gets me closer, but the scripts behave differently now on OS X.  For 
example, printf's don't output the same.

Try searching on google and find out exactly what sh MacOSX is using. 
Then you'd have a better idea on what you're working with.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread Chuck Swiger
Hi--

On Jan 25, 2012, at 7:24 PM, Da Rock wrote:
 On 01/26/12 12:55, Doug Poland wrote:
 This gets me closer, but the scripts behave differently now on OS X.  For 
 example, printf's don't output the same.
 
 Try searching on google and find out exactly what sh MacOSX is using. Then 
 you'd have a better idea on what you're working with.

/bin/sh on MacOSX is:

$ /bin/sh --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.

...and it has been using bash as /bin/sh since 10.2 or so.

Anyway, running bash as /bin/sh versus as /bin/bash likely affects whether it 
invokes printf as a builtin(1) command or as an external command.  It's 
possible that invoking /usr/bin/printf instead of just printf in the scripts 
might resolve the issue(s).

Regards,
-- 
-Chuck

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread mikel king

On Jan 25, 2012, at 5:08 PM, Doug Poland wrote:

 Hello,
 
 I'm trying port some shell scripts to FreeBSD that were originally
 written on Darwin (OS X).
 
 The issue I'm having is the shebang line of the scripts in OS X is
 #!/bin/sh, and it turns out that is really an instance of bash, and
 the code contains some bashisms.  On FreeBSD I have bash in
 /usr/local/bin/bash.
 
 Is there an easy/best way to have a single shebang that works on
 both OS's?  I'd rather not change FreeBSD's bourne shell to bash with
 any symlinking of /usr/local/bin/bash to /bin/sh.
 
 
 -- 
 Regards,
 Doug


Mac OS X defaults to /bin/bash but things get weird because sh on mac is also 
bash. Funnily enough a complete separate binary and not a symlink. Anyway, this 
means things written for the Mac may not work directly on FreeBSD. What I mean 
is that bash3 syntax is not going to be backwardly compatible with sh. If you 
wish to retain the bashiness of the scripts then the easiest option would be to 
install the bash (3.x) port and use env to invoke the appropriate shell on each 
system.

Regards,
Mikel King
BSD News Network
http://bsdnews.net
skype: mikel.king
http://twitter.com/mikelking



___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread Devin Teske

On Jan 25, 2012, at 8:13 PM, Chuck Swiger wrote:

 Hi--
 
 On Jan 25, 2012, at 7:24 PM, Da Rock wrote:
 On 01/26/12 12:55, Doug Poland wrote:
 This gets me closer, but the scripts behave differently now on OS X.  For 
 example, printf's don't output the same.
 
 Try searching on google and find out exactly what sh MacOSX is using. Then 
 you'd have a better idea on what you're working with.
 
 /bin/sh on MacOSX is:
 
 $ /bin/sh --version
 GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
 Copyright (C) 2007 Free Software Foundation, Inc.
 
 ...and it has been using bash as /bin/sh since 10.2 or so.
 
 Anyway, running bash as /bin/sh versus as /bin/bash likely affects whether it 
 invokes printf as a builtin(1) command or as an external command.  It's 
 possible that invoking /usr/bin/printf instead of just printf in the scripts 
 might resolve the issue(s).
 

If that's the problem, perhaps a trick can do:

printf(){builtin printf $@;}

At the top after the she-bang. Should cause all invocations to use built-in 
versus otherwise by defining a function that explicitly calls the built-in.
-- 
Devin

_
The information contained in this message is proprietary and/or confidential. 
If you are not the intended recipient, please: (i) delete the message and all 
copies; (ii) do not disclose, distribute or use the message in any manner; and 
(iii) notify the sender immediately. In addition, please be aware that any 
message addressed to our domain is subject to archiving and review by persons 
other than the intended recipient. Thank you.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Portability of shell scripts from other *nixes

2012-01-25 Thread Karl Vogel
 On Wed, 25 Jan 2012 16:08:07 -0600, 
 Doug Poland d...@polands.org said:

D I'm trying port some shell scripts to FreeBSD that were originally
D written on Darwin (OS X).  The issue I'm having is the shebang line of
D the scripts in OS X is #!/bin/sh, and it turns out that is really an
D instance of bash, and the code contains some bashisms.  On FreeBSD I
D have bash in /usr/local/bin/bash.

D Is there an easy/best way to have a single shebang that works on both
D OS's?  I'd rather not change FreeBSD's bourne shell to bash with any
D symlinking of /usr/local/bin/bash to /bin/sh.

   Do you have the Korn shell installed?  I've found that to be a nice
   compromise for scripts that have bash-isms.

-- 
Karl Vogel  I don't speak for the USAF or my company

Texted a friend meaning to ask if she was busy.
Me: Are you busty?  Her: They're manageable, what's up?
 --Jimmy Fallon, #textingdisaster tweets, 13 Jan 2012
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org