gpt4 book ai didi

ruby - 如何在 ruby​​ 脚本中重新加载 .profile

转载 作者:太空宇宙 更新时间:2023-11-04 04:00:54 25 4
gpt4 key购买 nike

我使用的是 Ruby 2,我资源了一些环境变量并将它们放入 ~/.profile 中,然后我在 ruby​​ 脚本中重新加载 .profile,如下所示:

#!/usr/bin/ruby env
`source ~/.profile`

但是我找不到源命令。如何在 ruby​​ 脚本中重新加载 .profile?

我也尝试过这个:

#!/usr/bin/ruby env
`/bin/bash -c 'source ~/.profile'`

但没有成功。

最佳答案

简而言之 - 你不能。

source 的环境变量只在子进程中有效,不会影响父进程。

唯一的方法是使用bash -c "source ~/.profile; env"返回环境变量,然后在脚本中解析和设置它们。

关于ruby - 如何在 ruby​​ 脚本中重新加载 .profile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23042296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com