$ PATH không cập nhật
Tôi đã vô tình xóa của mình ~/.bashrctrên máy Ubuntu của mình và bây giờ bất cứ khi nào tôi nhập một lệnh trên thiết bị đầu cuối, nó sẽ gây cho tôi lỗi này:
The command could not be located because '/usr/bin:/bin' is not included in the PATH environment variable.
Tôi đã thử thêm export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbinvào ~/.bashrc, nhưng tôi vẫn gặp phải vấn đề tương tự.
Tôi có thể export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbinsử dụng thiết bị đầu cuối và nó hoạt động tốt, nhưng tôi phải thực hiện thủ công mỗi khi mở một thiết bị đầu cuối mới. đó có phải là cách giải quyết?
Nội dung ~ / .bashrc:
case $- in *i*) ;; *) return;; esac HISTCONTROL=ignoreboth shopt -s histappend HISTSIZE=1000 HISTFILESIZE=2000 shopt -s checkwinsize [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot)
fi
case "$TERM" in xterm-color|*-256color) color_prompt=yes;; esac 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 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" ;; *) ;; esac 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 alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' 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$//'\'')"' if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi 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 export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin export POCL_DEBUG=0 export POCL_DEVICES=rsim export POCL_CACHE_DIR=$HOME/temp_pocl
export REDEFINE_HOME=$HOME/redefine/ export POCL_LEAVE_KERNEL_COMPILER_TEMP_FILES=1 export PATH=$PATH:/home/harry/redefine/bin/riscv32-gcc/bin
export LLVM_PATH=$HOME/llvm-project/build/bin export PATH=$HOME:$LLVM_PATH
Trả lời
Trước hết, bạn nên xóa các PATHkhai báo của mình khỏi ~/.bashrc. Bạn không muốn chúng chạy lại mỗi khi bạn mở một trình bao mới! Loại định nghĩa biến toàn cục này thuộc về ~/.profile hoặc, nếu tệp tồn tại ~/.bash_profile,.
Bây giờ, vấn đề bạn đang gặp phải là do nhiều khai báo PATH mà bạn có đang ghi đè lẫn nhau. Đây là những dòng có liên quan:
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
export PATH=$PATH:/home/harry/redefine/bin/riscv32-gcc/bin export LLVM_PATH=$HOME/llvm-project/build/bin
export PATH=$HOME:$LLVM_PATH
Đó là 4 lệnh, mỗi lệnh sẽ được chạy tuần tự. Hãy xem điều gì sẽ xảy ra nếu chúng ta chạy chúng trong một thiết bị đầu cuối:
$ export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin $ echo $PATH /bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin $ export PATH=$PATH:/home/harry/redefine/bin/riscv32-gcc/bin $ echo $PATH /bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/home/harry/redefine/bin/riscv32-gcc/bin $ export LLVM_PATH=$HOME/llvm-project/build/bin $ export PATH=$HOME:$LLVM_PATH
$ echo $PATH
/home/terdon:/home/terdon/llvm-project/build/bin
Như bạn có thể thấy ở trên, exportlệnh cuối cùng của bạn ghi đè các thay đổi trước đó bạn đã thực hiện và đặt PATHđể chỉ chứa $HOMEdir của bạn (điều này không có ý nghĩa, bạn không muốn của mình $HOMEtrong PATH!) Và của bạn $LLVM_PATH. Những gì bạn muốn làm là thêm các $LLVM_PATHđến $PATH, vì vậy bạn thay vì cần phải có này:
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/home/harry/redefine/bin/riscv32-gcc/bin
export LLVM_PATH="$HOME"/llvm-project/build/bin
export PATH="$PATH:$LLVM_PATH"
Vì vậy, hãy xóa tất cả các PATHđịnh nghĩa khỏi của bạn ~/.bashrcvà ~/.profilethay vào đó thêm ba dòng ở trên vào của bạn .