如何在当前 shell 的上下文中执行 Ruby 系统调用

How to execute a Ruby system call in the context of the current shell

我正在从 Ruby 脚本中执行对 rvm use ... 的调用:

system "rvm use 2.5.5"

当上述执行时,我得到

RVM is not a function, selecting rubies with 'rvm use ...' will not work.  

You need to change your terminal emulator preferences to allow login shell.

我相当确定我是以登录名登录的shell。在我打开的终端中使用正常的 RVM 命令没有问题。 system 命令是在当前 shell 上获取还是默认使用其他内容?如果它使用其他东西,在当前 shell 的上下文中将命令 Ruby 变为 运行 的最佳方法是什么?

这些事情对于 RVM 来说可能很棘手。试试这个:

"/bin/bash -c -l 'rvm use 2.5.5 && <add your system commands here>'"

注意:我猜它会创建一个 new shell 环境。您真的需要访问您的 current shell 吗?