.bashrc 경로를 항상 표시하는 터미널 창을 수정하는 방법은 무엇입니까?

.bashrc 경로를 항상 표시하는 터미널 창을 수정하는 방법은 무엇입니까?

시스템: Linux Mint 20(우분투)

그래서 얼마 전 C/C++용 wasm 컴파일러 emscripten을 설치했는데 bashrc에 경로를 추가하면 항상 새 터미널 셸이 시작되고 경로가 추가되었고 터미널의 사용자 색상이 변경되었음을 알려주는 것 같습니다.

이렇게 하면 이 문제를 해결할 수 있고 source ~/.bashrc정상적인 색상이 돌아올 것입니다. 하지만 여기서 정확히 무슨 일이 일어나고 있는지, 그리고 가능한 해결책이 있는지 알고 싶습니다.

다음은 어떻게 보이는지 보여주는 몇 가지 스크린샷입니다.

소스 완성 후 ~/.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 nvmnvm 명령이 작동합니다.

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다음 실행됩니다. 또한 파일 맨 위에 에코를 넣었으며 파일 소스를 실행할 때까지 실행되지 않습니다.

다음과 같습니다.

새로운

편집 #4 죄송합니다. 내용이 너무 길지만, 이 파일이 문제를 일으키는지 궁금합니다.

.bash_config 파일

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정말 고통스럽기 때문입니다.

관련 정보