~/.profile 和 ~/.bash_profile 有什么区别?

lak*_*esh 100 bash profile

~/.profile和 和有~/.bash_profile什么区别?

bah*_*mat 71

.profile是 Bourne shell(又名,sh)的原始配置文件配置。bash,作为 Bourne 兼容的 shell 将读取和使用它。在.bash_profile另一方面,仅被读取bash。它适用于与标准 Bourne shell 不兼容的命令。

  • 您可以从 [UNIX Shell History](http://www.softpanorama.org/People/Shell_giants/introduction.shtml) 开始。 (5认同)
  • @lakesh:是的,任何提供 bourne 兼容性的 shell 都会读取 `.profile`。例如,`bash` 和 `ksh` 而不是 `csh` 或 `tcsh`。并且 `zsh` 提供了 `sh` 和 `csh` 兼容性,因此它可以读取 `.profile` 和 `.login`,以及 `zsh` 特定的点文件。 (2认同)

Mik*_*kel 43

原始sh来源.profile在启动时。

bash.bash_profile首先尝试 source ,但如果不存在,它将 source .profile1

请注意,如果bash以 开头sh(例如,/bin/sh是指向 的链接/bin/bash)或以--posix标志开头,它会尝试模拟sh,并且只读取.profile

脚注:

  1. 实际上,第一个.bash_profile, .bash_login,.profile

也可以看看:

  • 太棒了……谢谢……尤其是参考文献…… (3认同)

Per*_*ulf 14

您知道 UNIX 世界中存在许多 shell,但其中大多数是:

  • Bourne 外壳:(/bin/sh发明者:Stephen Bourne)
  • BASH(Bourne Again Shell):(/bin/bash发明者:Brian Fox,在GNU项目下)(强大的shell)
  • C shell :(/bin/csh发明者:Bill Joy,TCP/IP 堆栈的发明者)
  • Korn shell:(/bin/ksh发明者:贝尔实验室的 David Korn)
  • Z壳:(/bin/zsh强大的壳)
  • TENEX C shell : /bin/tcsh(派生自 C Shell)
  • Debian Almquist shell :(/bin/dash派生自Almquist shell(NetBSD项目下的ash))(Dash来自lenny)

但你的问题是关于~/.bash_profile~/.profile

当您登录到 UNIX 机器时,它会根据管理员在最后一个字段中选择的 shell 重定向到您的主目录,/etc/passwd例如:

mohsen:x:1000:1000:Mohsen Pahlevanzadeh,,,:/home/mohsen:/bin/bash
Run Code Online (Sandbox Code Playgroud)

您的 shell 运行,默认情况下每个 shell 都有一个用于login和的设置文件logout。当您登录 bash 时,~/.profile会运行,当您登录时logout~/.bash_logout会运行。 ~/.bash_history文件保留您的输入命令。

每个shell中的初始化文件

TENEX C 外壳

  • ~/.login 当您登录时
  • ~/.logout 当您退出时
  • ~/.tcshrc~./bashrcbash 一样

您可以将变量设置$histfile为历史文件的名称,将变量设置为$history要保留的命令数。

Z壳

事实上,它是一个强大的 shell,如果你有空闲时间,一定要迁移到它。

除了其他shell,Z shell还有很多配置文件和初始化文件,我就这么写:

$ZDOTDIR/.zshenv
$ZDOTDIR/.zprofile
$ZDOTDIR/.zshrc
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout
/tmp/zsh*
/etc/zshenv
/etc/zprofile
/etc/zshrc
/etc/zlogin
Run Code Online (Sandbox Code Playgroud)

注意:如果未$ZDOTDIR设置,则设置主页。

C壳

注意:TENEX C shell 是从 C shell 分叉出来的。BSD 支持 C shell。如果您熟悉 C 语言编程,您应该会很舒服,因为它的语法是相似的。

~/.login
~/.cshrc
~/.logout
Run Code Online (Sandbox Code Playgroud)

注意:csh 是旧的。请改用 tcsh。

科恩壳牌

  • ~/.profile
  • rc 文件:用户定义
  • 注销文件:不适用

伯恩再次壳 (BASH)

它是非常强大的 shell,在 GNU 项目下诞生,由 Bourne Shell 分叉。

~/.bash_login
~/.bash_logout
~/.bashrc
~/.bash_profile
~/.bash_history
Run Code Online (Sandbox Code Playgroud)

当您登录时,bash 运行~/.bash_profile~/.bash_profile运行~/.bashrc. 确实~/.bashrc不是 bash 初始化文件,因为 bash 不运行它。

伯恩壳

它死了。甚至当你使用时man sh,你会看到dash. [编者注:关于这一点dash仅适用于 Debian 和基于 Debian 的发行版,如 Ubuntu。]

你的答案

~/.bash_profile在 bash~/.profile下工作,但在 Bourne 和 Korn shell 下工作。

  • Chet Ramey 是 Bash 的主要开发者。 (2认同)

anz*_*eth 6

登录 shell 只是一个 shell,您可以通过它 ssh 或在控制台登录。非登录外壳是某人也无法登录的外壳。程序/系统服务通常使用非登录 shell。

至于你的第三点。确实.bashrc是在 shell 的每个实例上执行。但是.bash_profile仅在登录时使用。这就是两个单独文件的原因。

.profile用于与 Bash 没有特别关系的事物,例如环境变量 $PATH 它也应该随时可用。.bash_profile专门用于登录 shell 或登录时执行的 shell。

  • .profile 用于与 Bash 没有特别关系的东西,比如环境变量 PATH 它也应该随时可用。.bash_profile 专门用于登录 shell 或登录时执行的 shell。 (2认同)