无法从shell脚本通过`RVM宝石use`改变RVM宝石 [英] Cannot change RVM gemset from shell script via `rvm gemset use`

查看:145
本文介绍了无法从shell脚本通过`RVM宝石use`改变RVM宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(见底部更新)

我觉得我失去了一些东西非常明显的在这里,但我不能从一个shell脚本中改变gemsets。这个最小脚本演示:

I feel like I'm missing something terribly obvious here, but I can't change gemsets from within a shell script. This minimal script demonstrates:

#!/usr/bin/env bash

rvm gemset use "testing"

我甚至尝试从脚本RVM页的说明(虽然似乎有必要也没有):

I even tried the instructions from the Scripting RVM page (although it didn't seem necessary):

#!/usr/bin/env bash

# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"
else
  printf "ERROR: An RVM installation was not found.\n"
fi

rvm gemset use "testing"

仍然没有去。

有趣的是,如果我尝试不首先创造了测试宝石运行脚本,我得到错误:宝石'测试'不存在,RVM宝石打造'测试'第一但是,如果我创建了宝石,然后运行该脚本,我没有得到任何输出脚本和宝石没有改变(根据 RVM信息) 。我能够完成的其他的RVM宝石的动作,如创建gemsets和信任 .rvmrc 文件,从脚本中。

Interestingly enough, if I try to run the script without first creating the "testing" gemset, I get ERROR: Gemset 'testing' does not exist, rvm gemset create 'testing' first. However, if I create the gemset and then run the script, I get no output from the script and the gemset is not changed (according to rvm info). I am able to perform other RVM gemset actions, such as creating gemsets and trusting .rvmrc files, from within the script.

[更新]

当然,环境的的变化,如通过电话从脚本中表示为 RVM信息。我如何获得这些改变持续存在/影响调用shell?或者,如果那是不可能的(指示<一个href=\"http://stackoverflow.com/questions/496702/can-a-shell-script-set-environment-variables-of-the-calling-shell\">here),有什么办法来设置当前RVM基于输入到一个脚本宝石?

Of course, the environment is changing, as indicated by a call to rvm info from within the script. How do I get these changes to persist/affect the calling shell? Or, if that's not possible (as indicated here), is there any way to set the current RVM gemset based on input to a script?

推荐答案

有完全相同的同样的问题,这里的解决方案:

Had exactly the same problem, and here's the solution:

#!/bin/bash

# IMPORTANT: Source RVM as a function into local environment.
#            Otherwise switching gemsets won't work.
[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"

# Enable shell debugging.
set -x

rvm 1.9.2@gemset_a
rvm gemdir
gem env gemdir

rvm 1.9.2@gemset_b
rvm gemdir
gem env gemdir

我所发现的是,你的交互shell得到了 RVM()及其助手,而脚本环境的并没有得到了他们。二进制,转而执行 RVM 部分工作,从而造成一些混乱。

What I've found out is that your interactive shell has got rvm() and its helpers, whereas script's environment has not got them. rvm binary is executed instead, partially working and thus causing some confusion.

这篇关于无法从shell脚本通过`RVM宝石use`改变RVM宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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