【问题标题】:if statement error while running source ~/.bashrc errorif 语句在运行 source ~/.bashrc 时出错
【发布时间】: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 $$ 更可靠(尽管它也可能令人困惑)。

标签: node.js linux bash


【解决方案1】:

我遇到了同样的问题。
首先我想明确一点,我是 Arch 和 Garuda 的新手,所以可能我的一些陈述并不完全正确。

正如有人在 cmets 中告诉您的,您正在使用 fish,请查看 Konsole 窗口的标题。或者编辑.bashrc 文件并将if 设置为fish 语法(将fi 更改为end),您会看到下一个错误清楚地告诉您您正在使用fish。

快速“修复”

运行bash切换到bash,然后你可以运行source ~/.bashrc

这样做的问题是,如果您退出 bash(通过执行exit)并返回到fish,您将失去执行source ~/.bashrc 所获得的东西。我的意思是,你必须继续使用 bash。

无需切换到 bash 的解决方案

使用nvm.fish

或者转换你需要的行(你的 bashrc 文件的最后 3 行)to fish syntax,并将它们添加到~/.config/fish/config.fish 文件中,然后运行source ~/.config/fish/config.fish

【讨论】:

    猜你喜欢
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 2019-01-09
    • 1970-01-01
    相关资源
    最近更新 更多