bah*_*mat 71
这.profile是 Bourne shell(又名,sh)的原始配置文件配置。bash,作为 Bourne 兼容的 shell 将读取和使用它。在.bash_profile另一方面,仅被读取bash。它适用于与标准 Bourne shell 不兼容的命令。
Mik*_*kel 43
原始sh来源.profile在启动时。
bash将.bash_profile首先尝试 source ,但如果不存在,它将 source .profile1。
请注意,如果bash以 开头sh(例如,/bin/sh是指向 的链接/bin/bash)或以--posix标志开头,它会尝试模拟sh,并且只读取.profile。
脚注:
.bash_profile, .bash_login,.profile也可以看看:
Per*_*ulf 14
您知道 UNIX 世界中存在许多 shell,但其中大多数是:
/bin/sh发明者:Stephen Bourne)/bin/bash发明者:Brian Fox,在GNU项目下)(强大的shell)/bin/csh发明者:Bill Joy,TCP/IP 堆栈的发明者)/bin/ksh发明者:贝尔实验室的 David Korn)/bin/zsh强大的壳)/bin/tcsh(派生自 C 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文件保留您的输入命令。
~/.login 当您登录时~/.logout 当您退出时~/.tcshrc和~./bashrcbash 一样您可以将变量设置$histfile为历史文件的名称,将变量设置为$history要保留的命令数。
事实上,它是一个强大的 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设置,则设置主页。
注意:TENEX C shell 是从 C shell 分叉出来的。BSD 支持 C shell。如果您熟悉 C 语言编程,您应该会很舒服,因为它的语法是相似的。
~/.login
~/.cshrc
~/.logout
Run Code Online (Sandbox Code Playgroud)
注意:csh 是旧的。请改用 tcsh。
~/.profile它是非常强大的 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 下工作。
登录 shell 只是一个 shell,您可以通过它 ssh 或在控制台登录。非登录外壳是某人也无法登录的外壳。程序/系统服务通常使用非登录 shell。
至于你的第三点。确实.bashrc是在 shell 的每个实例上执行。但是.bash_profile仅在登录时使用。这就是两个单独文件的原因。
.profile用于与 Bash 没有特别关系的事物,例如环境变量 $PATH 它也应该随时可用。.bash_profile专门用于登录 shell 或登录时执行的 shell。