digitalmars.D - [OT] Shell scripting compatibility
- Nick Sabalausky (3/3) Jul 04 2009 Can /bin/bash safely be expected to exist on all non-Windows systems tha...
- Adam D. Ruppe (9/12) Jul 04 2009 I know on FreeBSD it is often in /usr/local/bin/bash (if it is installed...
- Nick Sabalausky (13/23) Jul 04 2009 That may work just fine in my case. I'm just using a batch-file (win) an...
- Jacob Carlborg (3/28) Jul 05 2009 #!/usr/bin/env bash
- Andrei Alexandrescu (15/58) Jul 05 2009 env is on all Unix platforms I tried, just sometimes it's in /bin/ and
- Jacob Carlborg (3/6) Jul 05 2009 What to watch out for when writing portable shell scripts:
- Steven Schveighoffer (6/9) Jul 06 2009 /bin/sh will always exist. Usually, it is a symlink to bash, but not
Can /bin/bash safely be expected to exist on all non-Windows systems that can compile D? Or is there something better for that? Any common cross-platform-scripting gotcha's to be aware of?
Jul 04 2009
On Sat, Jul 04, 2009 at 04:50:22PM -0400, Nick Sabalausky wrote:Can /bin/bash safely be expected to exist on all non-Windows systems that can compile D? Or is there something better for that? Any common cross-platform-scripting gotcha's to be aware of?I know on FreeBSD it is often in /usr/local/bin/bash (if it is installed at all), so you can't really rely on it being at /bin/bash. I don't really have a solution to cover the differences though. I guess you could write simple, minimal scripts and just use /bin/sh for best cross platform luck. -- Adam D. Ruppe http://arsdnet.net
Jul 04 2009
"Adam D. Ruppe" <destructionator gmail.com> wrote in message news:mailman.5.1246741099.14071.digitalmars-d puremagic.com...On Sat, Jul 04, 2009 at 04:50:22PM -0400, Nick Sabalausky wrote:That may work just fine in my case. I'm just using a batch-file (win) and a shell script (non-win) to launch rebuild to compile the real cross-platform, umm "script", that's written in D. And even then, only for the cases where the included precompiled versions are insufficient, such as on a non-x86 or a mac (my only mac isn't current anymore. and it's completely dead.). So it is fairly trivial script. So sh is typically in that location then? I know Unix doesn't really have a way (at least to my knowledge) to handle a script needing a particular interpreter that could be in different places on different machines without requiring the user to make a symlink or something. But I don't really need perfect. Good enough is good enough here :)Can /bin/bash safely be expected to exist on all non-Windows systems that can compile D? Or is there something better for that? Any common cross-platform-scripting gotcha's to be aware of?I know on FreeBSD it is often in /usr/local/bin/bash (if it is installed at all), so you can't really rely on it being at /bin/bash. I don't really have a solution to cover the differences though. I guess you could write simple, minimal scripts and just use /bin/sh for best cross platform luck.
Jul 04 2009
On 7/5/09 6:36 AM, Nick Sabalausky wrote:"Adam D. Ruppe"<destructionator gmail.com> wrote in message news:mailman.5.1246741099.14071.digitalmars-d puremagic.com...but that requires env, I don't know if that's any better.On Sat, Jul 04, 2009 at 04:50:22PM -0400, Nick Sabalausky wrote:That may work just fine in my case. I'm just using a batch-file (win) and a shell script (non-win) to launch rebuild to compile the real cross-platform, umm "script", that's written in D. And even then, only for the cases where the included precompiled versions are insufficient, such as on a non-x86 or a mac (my only mac isn't current anymore. and it's completely dead.). So it is fairly trivial script. So sh is typically in that location then? I know Unix doesn't really have a way (at least to my knowledge) to handle a script needing a particular interpreter that could be in different places on different machines without requiring the user to make a symlink or something. But I don't really need perfect. Good enough is good enough here :)Can /bin/bash safely be expected to exist on all non-Windows systems that can compile D? Or is there something better for that? Any common cross-platform-scripting gotcha's to be aware of?I know on FreeBSD it is often in /usr/local/bin/bash (if it is installed at all), so you can't really rely on it being at /bin/bash. I don't really have a solution to cover the differences though. I guess you could write simple, minimal scripts and just use /bin/sh for best cross platform luck.
Jul 05 2009
Jacob Carlborg wrote:On 7/5/09 6:36 AM, Nick Sabalausky wrote:env is on all Unix platforms I tried, just sometimes it's in /bin/ and some other times it's in /usr/bin. I know of no portable way to search the path and run a program from the shebang on Unix. Second, you can't pass options to a program, for example: won't work because the shell will pass "--chatty -O" as one single option to rdmd. I worked around that by requiring --shebang if you want to pass multiple parameters from within the shebang line: Then rdmd detects that the argument "--shebang --chatty -O" starts with --shebang and therefore splits the rest and parses them as flags. Very annoying. By the way, I recently changed rdmd to... but let me make a different post. Andrei"Adam D. Ruppe"<destructionator gmail.com> wrote in message news:mailman.5.1246741099.14071.digitalmars-d puremagic.com...but that requires env, I don't know if that's any better.On Sat, Jul 04, 2009 at 04:50:22PM -0400, Nick Sabalausky wrote:That may work just fine in my case. I'm just using a batch-file (win) and a shell script (non-win) to launch rebuild to compile the real cross-platform, umm "script", that's written in D. And even then, only for the cases where the included precompiled versions are insufficient, such as on a non-x86 or a mac (my only mac isn't current anymore. and it's completely dead.). So it is fairly trivial script. So sh is typically in that location then? I know Unix doesn't really have a way (at least to my knowledge) to handle a script needing a particular interpreter that could be in different places on different machines without requiring the user to make a symlink or something. But I don't really need perfect. Good enough is good enough here :)Can /bin/bash safely be expected to exist on all non-Windows systems that can compile D? Or is there something better for that? Any common cross-platform-scripting gotcha's to be aware of?I know on FreeBSD it is often in /usr/local/bin/bash (if it is installed at all), so you can't really rely on it being at /bin/bash. I don't really have a solution to cover the differences though. I guess you could write simple, minimal scripts and just use /bin/sh for best cross platform luck.
Jul 05 2009
On 7/4/09 10:50 PM, Nick Sabalausky wrote:Can /bin/bash safely be expected to exist on all non-Windows systems that can compile D? Or is there something better for that? Any common cross-platform-scripting gotcha's to be aware of?What to watch out for when writing portable shell scripts: http://www.linux.com/archive/articles/34658
Jul 05 2009
On Sat, 04 Jul 2009 16:50:22 -0400, Nick Sabalausky <a a.a> wrote:Can /bin/bash safely be expected to exist on all non-Windows systems that can compile D? Or is there something better for that? Any common cross-platform-scripting gotcha's to be aware of?/bin/sh will always exist. Usually, it is a symlink to bash, but not always. Even if it's not bash, it should generally allow 99% of what you want to do with bash. I wrote shell scripts for busybox's ash (/bin/sh) and those scripts ran seamlessly on a full linux system with bash. -Steve
Jul 06 2009