如何解决bash_profile中的错误模式问题?

时间:2015-01-28 19:09:12

标签: .bash-profile oh-my-zsh dotfiles

我的终端输出了错误的图案:

   ➜  ~  source .bash_profile
load_dotfiles:1: bad pattern: files=(\n        /Users/xeLL/.rvm/scripts/rvm # Load RVM into a shell session *as a function*\n        /Users/xeLL/.dotfiles/shell/bash_options # Options\n        /Users/xeLL/.dotfiles/shell/bash_exports # Exports\n        /Users/xeLL/.dotfiles/shell/bash_aliases # Aliases\n        /Users/xeLL/.dotfiles/shell/functions/* # Functions\n        /Users/xeLL/.dotfiles/shell/bash_prompt # Custom bash prompt\n        /Users/xeLL/.dotfiles/shell/bash_paths # Path modifications\n        /usr/local/etc/bash_completion # Bash completion (installed via Homebrew)\n        /Users/xeLL/.bash_profile.local # Local and private settings not under version control (e.g. git credentials)\n    )
   ➜  ~

这是bash_profile的一部分:

load_dotfiles() {
declare -a files=(
    $HOME/.rvm/scripts/rvm # Load RVM into a shell session *as a function*
    $HOME/.dotfiles/shell/bash_options # Options
    $HOME/.dotfiles/shell/bash_exports # Exports
    $HOME/.dotfiles/shell/bash_aliases # Aliases
    $HOME/.dotfiles/shell/functions/* # Functions
    $HOME/.dotfiles/shell/bash_prompt # Custom bash prompt
    $HOME/.dotfiles/shell/bash_paths # Path modifications
    $(brew --prefix)/etc/bash_completion # Bash completion (installed via Homebrew)
    $HOME/.bash_profile.local # Local and private settings not under version control (e.g. git credentials)
)

# if these files are readable, source them
for index in ${!files[*]}
do
    if [[ -r ${files[$index]} ]]; then
        source ${files[$index]}
    fi
done

}

对此有何想法? 我也在使用oh-my-zsh和OS X Yosemite。

1 个答案:

答案 0 :(得分:1)

我修改了您的商家信息(删除了'$(brew --prefix)'行)并更改了:

source ${files[$index]}

echo "source ${files[$index]}"

您的功能在我的Linux系统上正常运行。那么如何定位问题/解决?

  1. 脚本中的任何“隐藏”代码? ## cat -v~ / some_bash_profile |更
  2. bash -n~ / some_bash_profile #Bash会在出现错误时抱怨
  3. 手动获取每一行#work ok?