简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM