编辑 .bash_profile 文件未生效

San*_*ath 0 linux bash fedora console

我需要放入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
Run Code Online (Sandbox Code Playgroud)

所以,我/root/.bash_profile像这样修改了文件:-

PATH=$PATH:$HOME/bin
export PATH
Run Code Online (Sandbox Code Playgroud)

PATH=$PATH:/opt/lampp/bin
export PATH
Run Code Online (Sandbox Code Playgroud)

但是,更改仍然没有生效 - 打开一个新的控制台并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
Run Code Online (Sandbox Code Playgroud)

PATH=$PATH:$HOME/bin
export PATH=$PATH:/opt/lampp/bin
Run Code Online (Sandbox Code Playgroud)

但它没有用。我错过了什么?

谢谢,
桑迪潘

Mad*_*ter 7

.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.
Run Code Online (Sandbox Code Playgroud)