我.bash_profile在我的/home/user目录中找不到Ubuntu 14.04 。我用ls -a命令查看了.bash_profile,但没有这样的文件。
nux*_*nux 120
Ubuntu 使用~/.profile.
你可以.bash_profile在 Ubuntu 中创建你的,但.profile不会被读取。
如果我们阅读 .profile 内容:
cat ~/.profile
Run Code Online (Sandbox Code Playgroud)
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
Run Code Online (Sandbox Code Playgroud)
所以用~/.profile代替~/.bash_profile
Rav*_*ina 12
调用登录 shell 时,bash 将按以下顺序查找其配置文件:
[0] ~/.bash_profile
[1] ~/.bash_login
[2] ~/.profile
Run Code Online (Sandbox Code Playgroud)
找到第一个后,将停止寻找其他人,所以如果有一个.bash_profile在我$HOME的bash不会寻找.bash_login和.profile了。
从这三个文件名中,Ubuntu 默认使用.profile您可以根据需要将其重命名为.bash_profile:
mv ~/.profile ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
现在,如果我们使用打开一个新的bash shell bash -l,su - $USER,sudo -u $USER -i或任何其他命令是运行bash作为登录shell,~/.bash_profile将得到采购。
到目前为止,我所谈论的仅适用于 Bash 本身,当您从 GUI 登录系统时,显示管理器负责获取正确的文件。
Ubuntu 使用gdm3它作为它的显示管理器,如果我们看一下:/etc/gdm3/Xsession我们可以看到除了.profile:
[0] ~/.bash_profile
[1] ~/.bash_login
[2] ~/.profile
Run Code Online (Sandbox Code Playgroud)
因此,如果您使用 GUI 登录,请将文件保留在.profile名称下,否则您可能会错过环境中的某些变量和设置。
我想更好的选择是创建一个符号链接.profile:
ln -s ~/.profile ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
现在您的数据存在于 中.profile,gdm不会遗漏任何内容,bash 加载.bash_profile实际上是.profile,并且通过编辑它们中的每一个,您都会得到相同的结果。
如果您还没有.profile,请从这里获取它的副本:
cp /etc/skel/.profile ~/.profile
Run Code Online (Sandbox Code Playgroud)
或者
mv ~/.profile ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
这意味着该文件不存在。但是,bash如果bash作为登录 shell 调用,您可以创建文件并执行/获取文件。因此,每次您通过 shell 登录时(例如通过ssh)。
如果您希望每次打开终端时都执行内容,则应.bashrc改为修改文件。
| 归档时间: |
|
| 查看次数: |
219567 次 |
| 最近记录: |