• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How the BASH Shell load its configuration files in Linux

by admin

BASH Shell will attempt to load several configuration files during the initialization. There are 2 sets of configuration files, depending it’s a login-shell, or non-login shell.

  • When you login a server on a bare metal monitor, or via SSH, or with # su – [username], you get a login shell.
  • When you start a shell in a terminal in an existing session (gnome-terminal, a shell inside another, or with # su [username]…), you get a non-login shell. A shell script is also executed under a non-login shell.

Below we’ll illustrate the difference by adding some debugging into those configuration files.

Login shell

By default, a login shell will load the following files:

# su - test
this is /etc/profile
this is ~/.bash_profile
this is ~/.bashrc
this is /etc/bashrc

Here note the ~/.bash_profile file, the file by default call ~/.bashrc, and ~/.bashrc call /etc/bashrc.

If for some reason BASH don’t find the file ~/.bash_profile, it will look for ~/.bash_login instead. If again ~/.bash_login cannot be found, BASH will look for ~/.profile instead.

And in the 2 cases, ~/.bashrc, and /etc/bashrc won’t be loaded, unless they were explicitly called in ~/.bash_login or ~/.profile.

The examples when ~/.bash_profile doesn’t exist:

– With presence of ~/.bash_login, no matter ~/.profile exist or not:

$ su - test
Password: 
this is /etc/profile
This is ~/.bash_login

– Only ~/.profile:

# su - test
this is /etc/profile
this is ~/.profile

Non-login Shell

It’s easier, BASH only load the ~/.bashrc, and again, the file call /etc/bashrc.

# su test
this is ~/.bashrc
this is /etc/bashrc

Filed Under: Linux

Some more articles you might also be interested in …

  1. How To Disable Or Extend System Logging Rate-limit on CentOS/RHEL 7
  2. Linux OS Service ‘syslog’
  3. fwupdmgr: command not found
  4. Linux OS Service ‘vncserver’
  5. Manual Changes Made To /etc/hosts Or /etc/sysconfig/network-scripts/ifcfg-* Are Lost
  6. chattr Command Examples to Change File Attributes (Make files immutable)
  7. How to set “max_report_luns” and “max_luns” on CentOS/RHEL 7 to scan more than 16,383 LUNs
  8. How to determine file and free space fragmentation of OCFS2
  9. CentOS / RHEL : How to configure iptable rules to allow FTP ports 20/21
  10. ack – A search tool like grep, optimized for developers (Command Examples)

You May Also Like

Primary Sidebar

Recent Posts

  • aws ec2: CLI for AWS EC2 (Command Examples)
  • aws cur – Create, query, and delete AWS usage report definitions (Command Examples)
  • aws configure – Manage configuration for the AWS CLI (Command Examples)
  • aws cognito-idp: Manage Amazon Cognito user pool and its users and groups using the CLI

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright