标签: .profile

为什么 ~/.bash_profile 在打开终端时没有得到来源?

问题

我有一个 Ubuntu 11.04 虚拟机,我想设置我的 Java 开发环境。我做了如下

  1. sudo apt-get install openjdk-6-jdk
  2. 将以下条目添加到~/.bash_profile

    export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
    
    export PATH=$PATH:$JAVA_HOME/bin
    
    Run Code Online (Sandbox Code Playgroud)
  3. 保存更改并退出

  4. 再次打开终端并输入以下内容

    echo $JAVA_HOME   (blank)
    echo $PATH        (displayed, but not the JAVA_HOME value)
    
    Run Code Online (Sandbox Code Playgroud)
  5. 什么也没发生,就像 JAVA_HOME 的导出和它添加到 PATH 从未完成一样。

解决方案

我不得不去~/.bashrc并在文件末尾添加以下条目

#Source bash_profile to set JAVA_HOME and add it to the PATH because for some reason is not being picked up
. ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

问题

  1. 为什么我必须这样做?我认为 bash_profile、bash_login 或 profile 在没有这两个的情况下会在 bashrc 之前首先执行。
  2. 在这种情况下,我的终端是非登录shell 吗?
  3. 如果是这样,为什么在终端之后执行 su 并输入密码时,它没有执行我还设置了上述导出的配置文件?

bash .profile environment-variables bashrc source

209
推荐指数
5
解决办法
36万
查看次数

我在 ubuntu 中找不到 .bash_profile

.bash_profile在我的/home/user目录中找不到Ubuntu 14.04 。我用ls -a命令查看了.bash_profile,但没有这样的文件。

bash .profile

94
推荐指数
3
解决办法
22万
查看次数

什么是登录和非登录 shell?

据说非登录shell的设置进入.bashrc文件和登录shell设置进入.profile文件。

登录和非登录 shell 的真正含义是什么?

请尽量不使用技术术语进行解释。

command-line bash login .profile

86
推荐指数
2
解决办法
7万
查看次数

为什么 /etc/profile.d/ 中的脚本被忽略(系统范围的 bash 别名)?

我是 Ubuntu 的新手。我正在运行 13.10 桌面版。

我想为 bash 设置一些系统范围的别名和自定义提示。我找到了这篇文章:

https://help.ubuntu.com/community/EnvironmentVariables

按照本文中的建议,我创建了 /etc/profile.d/profile_local.sh。它归 root 所有,并且与那里的其他脚本一样具有 644 的权限:

root@ubuntu:/etc/profile.d# ll
total 28
drwxr-xr-x   2 root root  4096 Mar 23 08:56 .
drwxr-xr-x 135 root root 12288 Mar 23 09:15 ..
-rw-r--r--   1 root root   660 Oct 23  2012 bash_completion.sh
-rw-r--r--   1 root root  3317 Mar 23 07:36 profile_local.sh
-rw-r--r--   1 root root  1947 Nov 23 00:57 vte.sh
Run Code Online (Sandbox Code Playgroud)

我进一步确认 /etc/profile 调用 /etc/profile.d。它包含以下代码块:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if …
Run Code Online (Sandbox Code Playgroud)

bash login .profile

75
推荐指数
2
解决办法
11万
查看次数

永久路径变量

我将如何使这个/media/De Soft/mongodb/binPATH 变量永久化?

每个人都在说“export PATH=$PATH:media/De\ Soft/mongodb/bin对您的~/.profile, 或.bashrc, 或.zshenv取决于您的外壳”。

我不知道什么是~/.profile、 或.bashrc、 或.zshenv。他们实际上是做什么的?

我将如何添加export PATH=$PATH:my/path到我的 .profile/.bashrc/.zshenv?

我正在使用带有默认终端的 64 位 Ubuntu 14.04 LTS。

bash .profile environment-variables bashrc mongodb

63
推荐指数
3
解决办法
20万
查看次数

为什么在打开终端时没有 .profile 来源?

刚刚安装了 Ubuntu 14.04.1 LTS。

根据.profile,

# ~/.profile: executed by the command interpreter for login shells. 
# This file is not read by bash, if ~/.bash_profile or ~/.bash_login exists.
Run Code Online (Sandbox Code Playgroud)

没有 ~/.bash_profile 或 ~/.bash_login。

打开终端时似乎没有来源 .profile 。

  1. 为什么在打开终端时不提供 .profile ?
  2. 如果没有来源,为什么 .profile 会在那里?
  3. 我如何知道/控制打开新终端时的来源?
  4. 当一个新终端打开时,它是否进行了“登录”?
  5. 将 $HOME/bin 添加到我的路径的好地方在哪里?.bashrc?由于 .profile 具有相同的代码,这会导致问题吗?

bash .profile environment-variables bashrc source

60
推荐指数
2
解决办法
6万
查看次数

登录时获取的脚本序列

我想将我所有的登录配置集中在我的~/.bash_profile. ~/.bashrc默认情况下有一个那里,但我用一个~/.bash_profile.

但是,当我登录时,在~/.bash_profile获取源之前的某些内容并显示以下内容:

Linux ubnt10-dev1 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Ubuntu 10.04.4 LTS

Welcome to the Ubuntu Server!
 * Documentation:  http://www.ubuntu.com/server/doc

  System information as of Fri May  9 12:17:39 EDT 2014

  System load:  0.01              Processes:           74
  Usage of /:   5.5% of 18.58GB   Users logged in:     0
  Memory usage: 4%                IP address for eth0: 123.x.x.x
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/

New …
Run Code Online (Sandbox Code Playgroud)

bash login .profile bashrc

48
推荐指数
1
解决办法
5万
查看次数

为什么在非登录 bash shell 会话期间未加载 /etc/profile?

对于 11.04,我重新安装了我的系统。该安装的一部分是安装rvm,它rvm.sh/etc/profile.d/. 这不起作用,因为/etc/profile(加载每个 +r in /etc/profile.d/*.sh)没有被加载。根据文档,该配置文件仅在登录时运行 bash 时才来源。为了验证这一点,我调用了bash --login,之后rvm就可用了。

这在没有任何配置的以前版本的 Ubuntu 中对我有用。也就是说,全新安装的 10.10 将正确获取 profile/.d。

我的问题是:我做错了什么,还是在 Natty 中做出的一些新假设破坏了这一点?我目前的解决方法是source /etc/profilein ~/.bashrc(这很糟糕,因为配置文件是bashrc之前加载的,但可以解决问题)。

rvm bash login .profile

47
推荐指数
2
解决办法
7万
查看次数

~/.profile 和 ~/.bashrc 里有什么?

我很难理解什么属于~/.profile以及什么属于~/.bashrc

根据我所读到的内容,在我看来,它~/.profile应该用于环境变量以及~/.bashrc别名、函数等。如果我将所有export语句从~/.bashrc移至~/.profile,一切是否都会按预期进行,或者我是否会破坏某些内容?

(如果您想查看这两个文件,这是我的 dotfiles 存储库。)

编辑 2022-06-03:我已将大部分环境变量从~/.bashrc移至~/.profile,并向自己保证~/.bash_profile来源~/.profile. 我留下的唯一环境变量~/.bashrc是那些仅在我在 shell 中工作时才重要的环境变量,例如,与 less、提示符、slrn 等相关的环境变量。一切似乎都进展顺利。谢谢您的帮助。

.profile bashrc

35
推荐指数
3
解决办法
1万
查看次数

为什么 Ubuntu 的默认 ~/.profile 源是 ~/.bashrc?

这些是~/.profile我的 13.10 附带的股票内容(已删除注释行):

if [ -n "$BASH_VERSION" ]; then
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
Run Code Online (Sandbox Code Playgroud)

这是从 Debian 继承的,但为什么 Canonical 决定保留它?据我所知,这不是标准的 *nix 方式,我见过各种系统都没有发生这种情况,所以我认为他们一定有充分的理由这样做。这可能会导致在运行登录 shell 时出现意外行为(例如,当 ssh 进入机器时),而用户不希望有~/.bashrc来源。

我能想到的唯一好处是不要将用户与许多启动文件混淆,并允许他们.bashrc单独编辑并读取该文件,而不管 shell 类型。然而,这是一个可疑的好处,因为为登录和交互式 shell 设置不同的设置通常很有用,这会阻止您这样做。此外,登录 shell 通常不在图形环境中运行,这可能会导致错误、警告和问题(天哪!),具体取决于您在这些文件中设置的内容。

那么为什么 Ubuntu 会这样做,我错过了什么?

bash design .profile bashrc

32
推荐指数
1
解决办法
1万
查看次数