系统:Linux Mint 20(ubuntu)
因此,前几天我安装了 emscripten 用于 C/C++ 的 wasm 编译器,添加到我的 bashrc 中的路径似乎总是启动一个新的终端 shell,并告诉我路径已添加并且终端上的用户颜色已更改。
我可以通过这样做来解决这个问题source ~/.bashrc
,并且正常颜色会恢复,但我想知道这里到底发生了什么以及是否有可能的解决方案?
以下是一些屏幕截图,向您展示它的外观:
任何见解或提示将非常感激!
编辑这些是您想要查看的文件:
.bashrc:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm|xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
if [[ ${EUID} == 0 ]] ; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
else
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '
fi
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h \w \$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
if [ -x /usr/bin/mint-fortune ]; then
/usr/bin/mint-fortune
fi
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
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
alias paper='. /home/doom/Desktop/Minecraft/Paper/paper'
export PATH=$PATH:"$USER/QT/5.15.1/gcc_64/bin"
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk"
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk/node/12.18.1_64bit/bin"
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk/upstream/emscripten"
source "/etc/profile.d/rvm.sh"
alias startPg='~/pgAdmin4/venv/bin/python ~/pgAdmin4/venv/lib/python3.8/site-packages/pgadmin4/pgAdmin4.py'
和 /etc/bash.bashrc :
# System-wide .bashrc file for interactive bash(1) shells.
# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, overwrite the one in /etc/profile)
# but only if not SUDOing and have SUDO_PS1 set; then assume smart user.
if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
# ;;
#*)
# ;;
#esac
# enable bash completion in interactive shells
#if ! shopt -oq posix; then
# if [ -f /usr/share/bash-completion/bash_completion ]; then
# . /usr/share/bash-completion/bash_completion
# elif [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
# fi
#fi
# sudo hint
if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; then
case " $(groups) " in *\ admin\ *|*\ sudo\ *)
if [ -x /usr/bin/sudo ]; then
cat <<-EOF
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
EOF
fi
esac
fi
# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
}
fi
编辑#2: 当我尝试仅运行从 nvm 命令开始的行时:
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
在该命令行之后# This loads nvm
,nvm 命令现在可以工作了。
我的yarn
命令之前不起作用,但运行后起作用:
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
即使在以下情况下,minecraft paper 服务器命令也不起作用:
alias paper='. /home/doom/Desktop/Minecraft/Paper/paper'
然而,该emcc
命令在尝试这些行之前和之后确实有效:
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk"
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk/node/12.18.1_64bit/bin"
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk/upstream/emscripten"
该startPg
命令之前不起作用,但输入后起作用:
alias startPg='~/pgAdmin4/venv/bin/python ~/pgAdmin4/venv/lib/python3.8/site-packages/pgadmin4/pgAdmin4.py'
所有这些命令在我执行后都有效source ~/.bashrc
编辑#3 所以我得到了一些有趣的结果,这是我的 bashrc 文件:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
echo 'am i here?'
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm|xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
if [[ ${EUID} == 0 ]] ; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
else
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '
fi
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h \w \$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
if [ -x /usr/bin/mint-fortune ]; then
/usr/bin/mint-fortune
fi
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
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
alias paper='. /home/doom/Desktop/Minecraft/Paper/paper'
export PATH=$PATH:"$USER/QT/5.15.1/gcc_64/bin"
echo 'hello world'
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk"
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk/node/12.18.1_64bit/bin"
export PATH=$PATH:"$HOME/doom/Desktop/RoseDevelopment/emsdk/upstream/emscripten"
echo 'hi'
# source "/etc/profile.d/rvm.sh"
alias startPg='~/pgAdmin4/venv/bin/python ~/pgAdmin4/venv/lib/python3.8/site-packages/pgadmin4/pgAdmin4.py'
我已经注释掉了rvm.在我这样做之前和之后它仍然有效,source ~/.bashrc
我认为这是因为在安装 rvm 时,它会将您置于一个 rvm 组中,该组可以访问我相信的命令。
emsdk (emcc) 路径上方和下方的回声不会打印出来,直到我运行,source ~/.bashrc
然后它们才会运行。我还在文件的最顶部放置了一个 echo,并且在我执行文件源之前它也不会运行。
它看起来是这样的:
编辑#4 很抱歉这已经很长了,但我很好奇这个文件是否会引起问题:
.bash_配置文件
source "/home/doom/Desktop/RoseDevelopment/emsdk/emsdk_env.sh"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
当我评论 rvm 行和 emsdk_env.sh 行时,回声消失了。rvm
命令仍然有效,但 emcc 命令不再有效。在我这样做之前,我仍然没有颜色输出source ~/.bashrc
,然后我的大多数其他命令 nvm/yarn/paper/startPg 再次工作。
这让我觉得我的 .bashrc 文件没有在新会话中加载?
看一下:
doom@doom-MacBookPro:~$ rvm
# It works here
doom@doom-MacBookPro:~$ yarn
-bash: yarn: command not found
doom@doom-MacBookPro:~$ rvm list
#This works here
doom@doom-MacBookPro:~$ emcc
-bash: emcc: command not found
doom@doom-MacBookPro:~$ paper
-bash: paper: command not found
doom@doom-MacBookPro:~$ nvm
-bash: nvm: command not found
doom@doom-MacBookPro:~$ source ~/.bashrc
am i here?
hello world
hi
doom@doom-MacBookPro ~ $ nvm
#This works here
doom@doom-MacBookPro ~ $ paper
#This works here
doom@doom-MacBookPro ~ $ yarn
#This works here
答案1
好吧,我可能终于想通了。从我的问题下面的评论来看。顺便说一下,谢谢@Criggie 和@msb。
run as command login shell
如果我按照 @user3584014 所做的作为这个问题的第二个答案,我什至可以在终端偏好设置中重新打开:https://askubuntu.com/questions/161249/bashrc-not-executed-when-opening-new-terminal
https://askubuntu.com/a/768359/1138077
这总结得很好:
In my case, simply the .bashrc loader lines were missing in .bash_profile
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
I added it manually and it worked with my fresh login
这使得我的所有命令(包括 emcc)都可以工作,并从一开始就恢复我的颜色。
Adding directories to PATH:
PATH += /home/doom/Desktop/RoseDevelopment/emsdk
PATH += /home/doom/Desktop/RoseDevelopment/emsdk/upstream/emscripten
PATH += /home/doom/Desktop/RoseDevelopment/emsdk/node/12.18.1_64bit/bin
Setting environment variables:
EMSDK = /home/doom/Desktop/RoseDevelopment/emsdk
EM_CONFIG = /home/doom/Desktop/RoseDevelopment/emsdk/.emscripten
EM_CACHE = /home/doom/Desktop/RoseDevelopment/emsdk/upstream/emscripten/cache
EMSDK_NODE = /home/doom/Desktop/RoseDevelopment/emsdk/node/12.18.1_64bit/bin/node
doom@doom-MacBookPro ~ $ emcc
emcc: error: no input files
doom@doom-MacBookPro ~ $ yarn -v
1.22.10
doom@doom-MacBookPro ~ $ rvm -v
Warning! PATH is not properly set up, /home/doom/.rvm/gems/ruby-2.5.3/bin is not at first place.
Usually this is caused by shell initialization files. Search for PATH=... entries.
You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
To fix it temporarily in this shell session run: rvm use ruby-2.5.3
To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
rvm 1.29.10 (manual) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
doom@doom-MacBookPro ~ $ nvm -v
0.36.0
doom@doom-MacBookPro ~ $
我仍然收到来自我的 emcc 命令回显
.bash_profile:
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
source "/home/doom/Desktop/RoseDevelopment/emsdk/emsdk_env.sh"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
然而,只要其他一切从一开始就正常工作,这就不是什么大问题,因为打开多个终端来处理事情,然后总是不得不做source ~/.bashrc
才是真正的痛苦。