Linux

編輯 .bash_profile 文件不生效

  • January 13, 2011

我需要放入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.

引用自:https://serverfault.com/questions/221949