zoukankan      html  css  js  c++  java
  • Bash: about .bashrc, .bash_profile, .profile, /etc/profile, etc/bash.bashrc and others

    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 the page I put together with the most important stuff from my .bashrc.profile and other files.

  • 相关阅读:
    第08组 Beta冲刺 (3/5)
    第08组 Beta冲刺 (2/5)
    第08组 Beta冲刺 (1/5)
    软工实践个人总结
    实验 7:OpenDaylight 实验——Python 中的 REST API 调用
    实验 6:OpenDaylight 实验——OpenDaylight 及 Postman 实现流表下发
    2020软工第二次结对作业
    实验 5 : OpenFlow 协议分析和 OpenDaylight 安装
    2020软工第一次结对作业
    实验 4:Open vSwitch 实验——Mininet 中使用 OVS 命令
  • 原文地址:https://www.cnblogs.com/bigben0123/p/3464785.html
Copyright © 2011-2022 走看看