如何修复 bash_profile 中的错误模式问题?

How to fix bad pattern issue in bash_profile?

我的终端出现错误模式输出:

   ➜  ~  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.

我修改了您的清单(删除了“$(brew --prefix)”行)并更改了:

source ${files[$index]}

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

您的函数在我的 Linux 系统上运行良好。那么如何定位issue/resolve?

  1. 您的脚本中有任何 'hidden' 代码吗? ## 猫-v ~/some_bash_profile |更多
  2. bash -n ~/some_bash_profile # Bash 如果错误
  3. 会报错
  4. 手动获取每一行 # 工作正常吗?