rvm bash脚本中的语法错误

问题描述 投票:0回答:3

我的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 <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]

UPDATE

〜/ .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

我期望“if”语句是问题所在。所以我这样做了。在if之前添加了这样的代码:

echo "Now lets try"
if ! type ruby > /dev/null 2>&1; then
  echo "trying"
fi
echo "tried"

如果,作为块中的第一行:echo“Now in if”

这是输出:

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 [email protected]: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 "$@" ; }
  }
bash rvm .bash-profile
3个回答
2
投票

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


2
投票

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

我没有看到Riaan Burger所说的“scm_breeze-line”。有没有人想出答案?

我的错误几乎是一样的:

/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      }

1
投票

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

从Win7切换到OSX后不久,我很乐意修改任何内容,而不必理解我在做什么。除此之外,我已经将.bashrc编辑为root(不是配置文件中的那个,而是位于/etc/.bashrc中的那个)和别名的cd

alias cd='cd -P'

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

我把这条线移到了~/.bash_profile,从那以后RVM愉快地运行而没有错误。

© www.soinside.com 2019 - 2024. All rights reserved.