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

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

问题描述

如何将环境变量从Ruby脚本导出到父shell?例如,实现一个天真的实现,读取 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天全站免登陆