解決 /usr/local/etc/bash_completion:59: command not found: shopt

Situation

打開 shell 出現以下 error:

/usr/local/etc/bash_completion:59: command not found: shopt
/usr/local/etc/bash_completion:1192: command not found: shopt
/usr/local/etc/bash_completion:1420: command not found: shopt
/usr/local/etc/bash_completion.d/minikube:type:2663: bad option: -t
/usr/local/etc/bash_completion.d/ssh:194: command not found: shopt
/usr/local/etc/bash_completion.d/ssh:247: command not found: shopt
/usr/local/etc/bash_completion.d/xrandr:17: parse error near `)'

Root Cause

為了 reuse 既有的 shell 配置,在 ~/.zshrc 裡直接 source ~/.bash_profile,但 ~/.bash_profile 裡有只有 bash 讀得懂的指令,zsh 無法處理。

Solution

  1. 把適用於 zsh 的部分獨立加到 ~/.zshrc 裡,而非 source 整個 ~/.bash_profile。
  2. 把跨 shell 的共通配置抽到另一個自訂的 rc 檔,這樣就可以讓 bash 或 zsh 引用。

例如:

################################
# File Name: ~/.common_shell_rc
# Purpose: Run commands for common shells
################################
alias ll='ls -al'
....

然後在 ~/.zshrc 裡引用:

$ vi ~/.zshrc

## 最後加上
source ~/.common_shell_rc

References

發表留言