【发布时间】:2021-12-31 11:02:56
【问题描述】:
我尝试运行source ~/.bashrc,但它显示
~/.bashrc (line 5): Missing end to balance this if statement
if [ -x /usr/bin/starship ]; then
^
from sourcing file ~/.bashrc
source: Error while reading file “/home/alokjha/.bashrc”
我该如何解决?
我目前在 Garuda Linux(arch linux 发行版)上,并且在这个 linux 世界中是新的,我想安装 nvm,我按照https://github.com/nvm-sh/nvm 中所写的步骤进行操作。我不熟悉 bash 语言,所以请帮忙(重启 PC 或终端没有帮助)
编辑:完成 BashRc 文件
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Load starship prompt if starship is installed
if [ -x /usr/bin/starship ]; then
__main() {
local major="${BASH_VERSINFO[0]}"
local minor="${BASH_VERSINFO[1]}"
if ((major > 4)) || { ((major == 4)) && ((minor >= 1)); }; then
source <("/usr/bin/starship" init bash --print-full-init)
else
source /dev/stdin <<<"$("/usr/bin/starship" init bash --print-full-init)"
fi
}
__main
unset -f __main
fi
# Advanced command-not-found hook
source /usr/share/doc/find-the-command/ftc.bash
# Aliasessource ~/.bashrc error
alias dir='dir --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias fixpacman="sudo rm /var/lib/pacman/db.lck"
alias grep='grep --color=auto'
alias grubup="sudo update-grub"
alias hw='hwinfo --short'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
alias psmem='ps auxf | sort -nr -k 4'
alias rmpkg="sudo pacman -Rdd"
alias tarnow='tar -acf '
alias untar='tar -zxvf '
alias upd='/usr/bin/update'
alias vdir='vdir --color=auto'
alias wget='wget -c '
# Help people new to Arch
alias apt-get='man pacman'
alias apt='man pacman'
alias helpme='cht.sh --shell'
alias please='sudo'
alias tb='nc termbin.com 9999'
# Cleanup orphaned packages
alias cleanup='sudo pacman -Rns `pacman -Qtdq`'
# Get the error messages from journalctl
alias jctl="journalctl -p 3 -xb"
# Recent installed packages
alias rip="expac --timefmt='%Y-%m-%d %T' '%l\t%n %v' | sort | tail -200 | nl"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
【问题讨论】:
-
我假设你不使用
bash。你可能使用fish。 -
那么如何使用 bash(我要求运行源命令)
-
@AlokJha
source的要点是在当前shell中运行脚本。如果当前的 shell 是 fish,那么你不能在其中运行 bash 脚本。您可以启动一个 bash shell 并在其中运行脚本,但它会破坏source的意义。所以,问题是,你为什么要source你的 .bashrc 文件?你到底想完成什么? -
做
echo $SHELL。如果它不返回 bash,请键入bash开始。这应该会自动执行您的 .bashrc,但如果您想获取它,您将能够。 -
@Nic3500
echo $SHELL不是找出您正在使用的外壳的可靠方法。它(通常)显示为当前用户帐户设置为默认的 shell,但这可能不是实际使用的。ps $$更可靠(尽管它也可能令人困惑)。