bash - 各种 shell 配置文件之间有什么区别?

标签 bash shell profile

~/.bashrc, ~/.bash_login, ~/.bash_logout, ~/.bash_profile, ~/.profile,/etc/profile,/etc/bash.bashrc,/etc/ssh/ssh_config 有什么区别和 sshd_config,它们何时加载以及它们的用途是什么?

最佳答案

bash 的手册页说有以下 bash shell 的初始化文件:

/etc/profile
      The systemwide initialization file, executed for login shells
/etc/bash.bashrc
      The systemwide per-interactive-shell startup file
/etc/bash.bash.logout
      The systemwide login shell cleanup file, executed when a login shell exits
~/.bash_profile
      The personal initialization file, executed for login shells
~/.bashrc
      The individual per-interactive-shell startup file
~/.bash_logout
      The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
      Individual readline initialization file

显然,不同的 shell(bash、zsh、csh 等)似乎有不同的配置文件。 shell 似乎与不同的 linux 和 unix 版本一样多:csh、ksh、bash、zsh、... Bash 有一个 .bashrc,Zsh 有一个 .zshrc等等。还可以区分登录 shell 和非登录 shell,以及系统范围的默认值和用户特定的默认值。

区分loginnon-login shell 是有意义的,因为有些命令应该只在登录时处理,而其他命令应该在每次打开新的 shell 时运行终端窗口。这就是 .bash_profile and .bashrc 之间的区别.对于 bash,.bashrc 会在您每次启动新的 bash 副本时重新加载,即当您启动新的 bash 但未登录时。 .bash_profile.profile 仅在您登录时加载。 bashrc 中的缩写 rc 代表“运行命令”或“运行控制”,是从旧的 Unix 系统采用的约定。

系统范围的默认值......

  • /etc/profile ..login shell,用于带登录的交互式 shell
  • /etc/bashrc ..非登录 Bash shells

主目录中的用户特定默认值 ~ for..

  • ~/.profile ..登录 shell,登录后调用
  • ~/.bashrc ..非登录 shell,如果已经登录
  • ~/.bash_profile ..login shell,在登录后调用(低优先级)

用于登录和注销的主目录中用户特定的默认值

  • ~/.bash_login ..登录 shell(登录时调用)
  • ~/.bash_logout ..登录 shell(在注销时调用)

以下链接很有帮助:.bashrc vs .bashprofile.bash_profile vs .bashrc , bash manual page (man bash)和 Zsh/Bash startup files loading order (.bashrc, .zshrc etc.) .

关于bash - 各种 shell 配置文件之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6372751/

相关文章:

arrays - Array Bash 在多个数组的循环中打印元素

bash - 获取当前子shell的pid

linux - Nginx init.d 脚本

http - 每个持久连接的 HTTP 内存使用

Wordpress 在用户配置文件仪表板上显示自定义 USERMETA 字段?

linux - grep/根据第一个文件中的列表从第二个文件中获取字符串

linux - bash重定向到同一个文件的一致性

shell - 以十六进制序列递归搜索二进制文件的目录?

php - 以 root 用户身份运行 PHP shell_exec()

ios - Xcode 的 Profiler 不显示符号名称