简体   繁体   English

是否可以在gem中包含Bash脚本?

[英]Is it possible to include a Bash script within a gem?

I'm creating a Ruby gem which I intend to publish on rubygems . 我正在创建一个Ruby gem,我打算在rubygems上发布。 Unfortunately, there's one thing I can't achieve with Ruby and that needs to be done with Bash ( controlling RVM from script ). 不幸的是,有一件事我用Ruby无法实现,而且需要用Bash( 从脚本控制RVM )来完成。

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? 是否可以在gem中包含Bash脚本,如果是,我将如何在gem的上下文中运行Ruby脚本?

It is possible, but the script can be executed only on unix-like environments, which include bash. 这是可能的,但脚本只能在类似unix的环境中执行,包括bash。 You can put the .sh into bin/ or share/ folders, and just call: 您可以将.sh放入bin/share/文件夹,然后只需调用:

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. 当然,您总是可以使用bundler gem模块来控制当前的gem而不是运行shell脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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