When/why to use --env-shebang with ruby gems?

别等时光非礼了梦想. 提交于 2020-05-15 04:08:46

问题


Ikenna Okpala recommended this .gemrc (I modified it slightly):

---
:verbose: true
:bulk_threshold: 1000
install: --no-ri --no-rdoc --env-shebang
:sources:
- http://gems.rubyforge.org/
:benchmark: false
:backtrace: false
update: --no-ri --no-rdoc --env-shebang
:update_sources: true

I had not noticed the --env-shebang before. I looked up the documentation for --env-shebang at http://guides.rubygems.org/command-reference/:

Install/Update Options:
...
-E, -​-[no-]env-shebang - Rewrite the shebang line on installed scripts to use /usr/bin/env

Practically speaking, why might the --env-shebang option be important? (I've never used it.)


回答1:


If for some reason the gem's author didn't use #!/usr/bin/env ruby you may well want to have it automatically changed.

(If you're asking why you'd want the env shebang line at all, this explains it pretty well.)

The beginning of the rubygems-developers thread discussing the idea for this feature is here.




回答2:


/usr/bin/env is a Unix program that checks a user's path to see how a program should be run. Using /usr/bin/env allows the person using the program to be able to choose their own version of Ruby rather than the one that might happen to be installed by default on the system. Rather than hardcoding a location for Ruby, you can let the user decide where it is.



来源:https://stackoverflow.com/questions/11495893/when-why-to-use-env-shebang-with-ruby-gems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!