Golang安装过程中更新bashrc文件时遇到错误怎么办
Golang安装过程中更新bashrc文件时遇到错误怎么办
/home/durai/.bashrc:16: command not found: shopt
/home/durai/.bashrc:24: command not found: shopt
/home/durai/.bashrc:127: command not found: shopt
/usr/share/bash-completion/bash_completion:45: command not found: shopt
/usr/share/bash-completion/bash_completion:53: command not found: complete
/usr/share/bash-completion/bash_completion:56: command not found: complete
/usr/share/bash-completion/bash_completion:59: command not found: complete
/usr/share/bash-completion/bash_completion:62: command not found: complete
/usr/share/bash-completion/bash_completion:65: command not found: complete
/usr/share/bash-completion/bash_completion:68: command not found: complete
/usr/share/bash-completion/bash_completion:71: command not found: complete
/usr/share/bash-completion/bash_completion:74: command not found: complete
/usr/share/bash-completion/bash_completion:77: command not found: complete
/usr/share/bash-completion/bash_completion:80: command not found: complete
/usr/share/bash-completion/bash_completion:1573: parse error near `|'
\[\e]0;\u@\h: \w\a\]\[\033[;32m\]┌──(\[\033[1;34m\]\u㉿\h\[\033[;32m\])-[\[\033[0;1m\]\w\[\033[;32m\]]\n\[\033[;32m\]└─\[\033[1;34m\]$\[\033[0m\]
更多关于Golang安装过程中更新bashrc文件时遇到错误怎么办的实战教程也可以访问 https://www.itying.com/category-94-b0.html
2 回复
# 在 .bashrc 文件中设置变量
# 请正确更改您的路径!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
并运行以下命令
sudo apt update && sudo apt install golang
更多关于Golang安装过程中更新bashrc文件时遇到错误怎么办的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
这个错误与Golang安装本身无关,而是bash shell配置问题。shopt和complete是bash内置命令,出现"command not found"通常是因为脚本在非bash shell中执行。
检查当前使用的shell:
echo $SHELL
如果显示的不是bash(比如是dash或sh),需要切换到bash:
bash
然后重新加载bashrc:
source ~/.bashrc
如果问题仍然存在,检查bashrc文件第16行、24行和127行附近的shopt命令使用。例如:
# 查看第16行附近内容
sed -n '10,20p' ~/.bashrc
# 典型的shopt用法应该是这样的:
shopt -s histappend
shopt -s checkwinsize
shopt -s globstar
对于bash_completion的错误,可能是由于在非交互式shell中执行了交互式配置。可以在bashrc开头添加检查:
# 在~/.bashrc文件开头添加
if [[ $- != *i* ]]; then
return
fi
如果使用的是dash作为默认shell,但想用bash,可以更改默认shell:
chsh -s /bin/bash
重新登录后问题应该解决。

