rvm bash脚本中的语法错误

时间:2014-09-01 12:58:34

标签: bash rvm .bash-profile

我的rvm无效,可能是因为错误。当我打开新的控制台时,它说:

-bash: /Users/amorfis/.rvm/scripts/cd: line 14: syntax error near unexpected token `('
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: `    cd()    { __zsh_like_cd cd    "$@" ; }'

很难说调用脚本.rvm/scripts/cd的位置。当我从~/.bash_profile删除此行时:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

没有错误。但是当我发出source $HOME/.rvm/scripts/rvm时......仍然没有错误。

我的系统是Mac OS X 10.9.4

rvm --version:

rvm 1.25.29 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

更新

〜/ .rvm / scripts中的其他脚本:

alias
aliases
autolibs
base
cd
cleanup
cli
completion
cron
db
disk-usage
docs
env
extras
fetch
fix-permissions
functions
gemsets
group
hash
help
hook
info
initialize
install
irbrc
irbrc.rb
list
maglev
manage
migrate
monitor
mount
notes
osx-ssl-certs
override_gem
patches
pkg
prepare
repair
requirements
rtfm
rubygems
rvm
set
snapshot
tools
upgrade
version
wrapper
zsh

我的~/.bash_profile看起来像这样:

#...not important stuff

source ~/.bashrc

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

在我~/.bashrc我有这条线(还有其他几条):

[ -s "/Users/amorfis/.scm_breeze/scm_breeze.sh" ] && source "/Users/amorfis/.scm_breeze/scm_breeze.sh"

当我删除此行时,错误也消失了。而且,当我运行source ~/.scm_breeze/scm_breeze.sh

时,它仍然无法显示

从这里安装Scm breeze:https://github.com/ndbroadbent/scm_breeze

source ~/.scm_breeze/scm_breeze.sh中有这样一段代码:

if ! type ruby > /dev/null 2>&1; then
  echo "Now in if"
  # If Ruby is not installed, fall back to the
  # slower bash/zsh implementation of 'git_status_shortcuts'
  source "$scmbDir/lib/git/fallback/status_shortcuts_shell.sh"
fi

我期待&#34;如果&#34;声明是问题所在。所以我这样做了。在if:

之前添加了此类代码
echo "Now lets try"
if ! type ruby > /dev/null 2>&1; then
  echo "trying"
fi
echo "tried"

并在内部,如果,作为块中的第一行:     echo&#34;现在进入&#34;

这是输出:

Now lets try
tried
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: syntax error near unexpected token `('
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: `    cd()    { __zsh_like_cd cd    "$@" ; }'

所以看起来scm_breeze.sh还可以。问题必须在.rvm中,但只有在运行scm_breeze.sh时才会出现。

更新2:

.rvm/scripts/cd脚本的开头如下所示:

#!/usr/bin/env bash

# Source a .rvmrc file in a directory after changing to it, if it exists.  To
# disable this feature, set rvm_project_rvmrc=0 in /etc/rvmrc or $HOME/.rvmrc
case "${rvm_project_rvmrc:-1}" in
1|cd)
  # clonned from git@github.com:mpapis/bash_zsh_support.git
  source "$rvm_scripts_path/extras/bash_zsh_support/chpwd/function.sh"

  # not using default loadign to support older Zsh
  [[ -n "${ZSH_VERSION:-}" ]] &&
  __rvm_version_compare "$ZSH_VERSION" -gt  4.3.4 ||
  {
    cd()    { __zsh_like_cd cd    "$@" ; }
    popd()  { __zsh_like_cd popd  "$@" ; }
    pushd() { __zsh_like_cd pushd "$@" ; }
  }

3 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。解决方案是确保scm_breeze行在所有rvm之后执行。

答案 1 :(得分:2)

我会将其添加为评论,但我没有这样做的声誉。我尝试了blob的答案,但是没有用。

我看不到Riaan Burger所说的“ scm_breeze行”。 有人找到了答案吗?

我的错误几乎相同:

/Users/myusername/.rvm/scripts/cd:14: defining function based on alias `cd'                                                       [ruby-2.3.3]
/Users/myusername/.rvm/scripts/cd:14: parse error near `()'

与第14行的内容相同:

11      [[ -n "${ZSH_VERSION:-}" ]] &&
12      __rvm_version_compare "$ZSH_VERSION" -gt  4.3.4 ||
13      {
14        cd()    { __zsh_like_cd cd    "$@" ; }
15        popd()  { __zsh_like_cd popd  "$@" ; }
16        pushd() { __zsh_like_cd pushd "$@" ; }
17      }

答案 2 :(得分:1)

今天遇到同样的问题,但在我的情况下问题与scm_breeze无关。如果有人从谷歌或其他地方偶然发现这个答案,也许它会帮助你。

从Win7切换到OSX后不久,我很乐意修改任何内容,而不必理解我在做什么。除此之外,我还是以root用户身份编辑了.bashrc(而不是个人资料中的那个,而是位于/etc/.bashrc中的那个),并为此区别cd

alias cd='cd -P'

在安装RVM之前从来没有遇到任何问题,所以如果你像以前一样快乐,那么过去是否给自己留下这样的礼物可能是值得的。

我已将所述行移至~/.bash_profile,从那时起RVM愉快地运行而没有错误。