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

B S*_*ven 60 bash .profile environment-variables bashrc source

刚刚安装了 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 具有相同的代码,这会导致问题吗?

mur*_*uru 50

  1. 因为默认情况下终端通常不运行登录 shell。他们通常也有运行登录 shell 的选项,这些 shell 执行 source .profile
  2. 控制登录 shell 的行为。
  3. 取决于外壳。有关bash,请参阅启动文件集
  4. 在某种意义上不是(例如,更新登录记录)。
  5. 如果您有一个名为binin的文件夹$HOME.profileUbuntu的默认设置会将其添加到您的PATH. 由于.profile是在登录时获取的(即使使用 GUI 登录),它应该是您PATH重新登录后启动的非登录 shell 的一部分。如果一个目录在 中出现两次也没有错PATH,有关详细信息,请参阅此 U&L 问题

  • 好的,现在说得通了。需要重新登录 GUI 以查看对 `.profile` 的更改。 (4认同)
  • @NiklasR https://askubuntu.com/a/598072/158442 (3认同)
  • @BSeven,您始终可以为每个命令行 shell 手动获取它:`. .profile` 或 `源 .profile`。 (2认同)
  • @BSeven 对于诸如“.”或“source”之类的 shell 命令,您可以使用“help”:“help .”,例如。一般来说,请参阅 TLDP [Bash 初学者指南,第 3 章](http://www.tldp.org/LDP/Bash-Beginners-Guide/html/chap_03.html)。Bash 初学者指南在某些地方有些过时,但作为起点是很好的。或者查看[我的其他答案之一](http://askubuntu.com/a/551711/158442)中的其他链接。 (2认同)

小智 22

我发现我必须编辑默认配置文件。在终端中,单击 Preferences > Profiles > Edit > Command > Run command as login shell

之后,新终端将获取.profile脚本。

在此处输入图片说明

  • IIUC 这是一个 hack,因为通常 .profile 应该是在启动 GUI 终端之前获取的,并且每次生成终端窗口时再次获取它是多余的。 (2认同)