在 Ruby 中导出环境变量 [英] Exporting an Environment Variable in Ruby

查看:25
本文介绍了在 Ruby 中导出环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将环境变量从 Ruby 脚本中导出到父 shell?例如,实现 read Bash 内置函数的简单实现:

How do I export an environment variable from within a Ruby script to the parent shell? For example, implementing a naïve implementation of the read Bash builtin:

#!/usr/bin/ruby

varname = ARGV[0]
ENV[varname] = STDIN.gets  # but have varname exported to the parent process

推荐答案

简单的回答:你不能.

更长的答案:你不能,除非操作环境提供了钩子来这样做.大多数没有.您通常能做的最好的事情就是打印出您想要完成的任务并让父母执行它们.

Longer answer: You can't, unless the operating environment provides hooks to do so. Most do not. The best you can usually do is print out the assignments you want done and have the parent execute them.

这篇关于在 Ruby 中导出环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆