Linux
編輯 .bash_profile 文件不生效
我需要放入
export PATH=$PATH:/opt/lampp/bin
我的~/.bash_profile
文件,以便命令行中的 mysql 在我的系統上工作。請檢查mysql 命令行不工作以獲取更多詳細資訊。我正在使用 Fedora 系統並以 root 使用者身份登錄。
如果我跑步,
locate .bash_profile
那麼我會得到這些:-/etc/skel/.bash_profile /home/sam/.bash_profile /home/sohil/.bash_profile /home/windows/.bash_profile /root/.bash_profile
所以,我修改了
/root/.bash_profile
這樣的文件: -從
PATH=$PATH:$HOME/bin export PATH
到
PATH=$PATH:/opt/lampp/bin export PATH
但是,更改仍然沒有生效 - 打開一個新的控制台並
mysql
再次執行說bash: mysql: command not found
。但是,
export PATH=$PATH:/opt/lampp/bin
在控制台中執行使其適用於該會話。.bash_profile
所以,我對文件做錯了什麼。可能是編輯不正確或編輯不正確。更新
在進行上述編輯之前,我還嘗試
export PATH=$PATH:/opt/lampp/bin
在末尾添加如下:-從
PATH=$PATH:$HOME/bin export PATH
到
PATH=$PATH:$HOME/bin export PATH=$PATH:/opt/lampp/bin
但它沒有用。我錯過了什麼?
謝謝,
桑迪潘
.bash_profile
只應該由登錄 shell 執行一次。.bashrc
是為每個孩子執行的文件。嘗試註銷並再次登錄,然後查看您的
.bash_profile
更改是否被拾取。只是為了章節和經文,這是來自 bash 的手冊頁:
When bash is invoked as an interactive login shell, or as a non-inter‐ active shell with the --login option, it first reads and executes com‐ mands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior. When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists. When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.