0
votes

I believe I've seen some examples of this in projects I use but I can not find them at this time. What I have is a ruby project with a structure such as this:

~/projects/ruby/foo/bin
     bar.rb
     bar.cmd
     bar.sh

My application sits entirely in bar.rb. I have logic in all of my file path logic to handle symbolic links, so that a symlink of ~/bin/bar will work correctly.

The issue I have is that I want this file to work the same on both windows and linux, therefore I took a shebang line out of bar.rb and would like to move it to bar.sh

#!/usr/bin/env ruby

But now I have to forward all os args from this bash file to the ruby file so that it will work correctly. I have not had much success on the windows cmd file either.

Is there a simpler way to achieve cross platform shebang behavior that works with os arguments?

1
Shebang isn't cross platform. What are you trying to do here? Just have .sh and .cmd entry points for your application? Do those scripts do any work? If not it would probably be better to just avoid them entirely. - Etan Reisner
I'm aware that shebang is not cross paltform, this is why I did not place it in bar.rb. The idea is that the .sh and .cmd files avoid the use of 'ruby file.rb [args]', instead make the file usable with 'bar [args]', so long as the shortcut to either the bash file or cmd file is on your PATH environment variable. I can supply a little more context of my application if necessary. - kwolfe
The ruby interpreter should ignore the shebang line on Windows as well so it should be portable in the sense that it is safe to leave there. And Windows tends to solve this sort of thing with default executables for extensions I believe (so just sticking bar.rb somewhere in %PATH% should be enough I think). - Etan Reisner

1 Answers

0
votes

For Linux, your bar.sh could look like (note: no shebang):

/bin/env ruby bar.rb "$@"

For Windows, your bar.cmd might look like:

ruby bar.rb %*

Note: the Windows version is untested.