博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Bash: about .bashrc, .bash_profile, .profile, /etc/profile, etc/bash.bashrc and others
阅读量:6324 次
发布时间:2019-06-22

本文共 1935 字,大约阅读时间需要 6 分钟。

Some interesting excerpts from the bash manpage:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile,~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
...
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.

As far as I understand, a login shell means a session where you log in to the system and directly end up in Bash, like a remote ssh session or logging in through a non-graphical text terminal. A non-login shell is then the type of shells you open after logging in: typically in a graphical session when you open a new terminal window.

How I think things are supposed to work (for a typical setup):

  • .profile is for things that are not specifically related to Bash, like environment variables PATH and friends, and should be available anytime. For example, .profile should also be loaded when starting a graphical desktop session.
  • .bashrc is for the configuring the interactive Bash usage, like Bash aliases, setting your favorite editor, setting the Bash prompt, etc.
  • .bash_profile is for making sure that both the things in .profile and .bashrc are loaded for login shells. For example, .bash_profile could be something simple like
    . ~/.profile. ~/.bashrc

    As stated in the man page excerpt above, if you would omit .bash_profile, only .profile would be loaded.

You might also be interested in .

转载地址:http://nqdaa.baihongyu.com/

你可能感兴趣的文章
URL地址传值型多条件搜索JS
查看>>
[翻译]CURAND Libaray--Host API--(2)
查看>>
Delphi xe5 编译报environment.proj错误的解决
查看>>
PHP变量作用域
查看>>
力挺8天入门wpf【转载】
查看>>
Linux模块
查看>>
kendo grid输入框验证方法
查看>>
[转]一致性哈希算法及其在分布式系统中的应用
查看>>
CAS与LDAP集成
查看>>
JQuery巧妙利用CSS操作打印样式
查看>>
(转载)JWebUnit做Web项目自动化测试
查看>>
牛气冲天的Iframe应用笔记
查看>>
emacs之配置etags-select
查看>>
搜索引擎(lucene及周边) 涉及的一些算法总结
查看>>
elasticsearch 口水篇(3)java客户端 - Jest
查看>>
VS2008 SP1 安装卡在 VS90sp1-KB945140-X86-CHS的解决方法
查看>>
wamp修改端口
查看>>
性能超越 Redis 的 NoSQL 数据库 SSDB
查看>>
[MFC] MFC 用mciSendString加载WAV资源文件
查看>>
将美丽无限放大,你会发现世界真的很美好!!!
查看>>