www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [OT] Shell scripting compatibility

reply "Nick Sabalausky" <a a.a> writes:
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
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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
parent reply "Nick Sabalausky" <a a.a> writes:
"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:
 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.
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 :)
Jul 04 2009
parent reply Jacob Carlborg <doob me.com> writes:
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...
 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.
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 :)
but that requires env, I don't know if that's any better.
Jul 05 2009
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
Jacob Carlborg wrote:
 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...
 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.
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 :)
but that requires env, I don't know if that's any better.
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
Jul 05 2009
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
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
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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