Nico Schuele
Nico Schuele

Reputation: 107

Is it possible to include a Bash script within a gem?

I'm creating a Ruby gem which I intend to publish on rubygems. Unfortunately, there's one thing I can't achieve with Ruby and that needs to be done with Bash (controlling RVM from script).

Is it possible to include a Bash script within a gem and if yes, how would I run the script from Ruby in the context of a gem?

Upvotes: 3

Views: 1521

Answers (1)

Малъ Скрылевъ
Малъ Скрылевъ

Reputation: 16514

It is possible, but the script can be executed only on unix-like environments, which include bash. You can put the .sh into bin/ or share/ folders, and just call:

name = 'your_gem_name'
g = Gem::Specification.find_by_name( name )
system( File.join( g.full_gem_path, 'share/myscript.sh' ) )

Of course, you always could use bundler gem module to control the current gems instead of running the shell script.

Upvotes: 2

Related Questions