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
- 把適用於 zsh 的部分獨立加到 ~/.zshrc 裡,而非 source 整個 ~/.bash_profile。
- 把跨 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
- linux 解决 " command not found: shopt "的 "~/.bashrc" 配置问题_独化蓝翅鸟,越岭万昆仑-CSDN博客
- bash – shopt command not found in .bashrc after shell updation – Stack Overflow
- Ubuntu 18.04解决执行source ~/.bashrc命令后出现/home/xxx/.bashrc:x: command not found: shopt错误 – 简书