리눅스 시스템에 로그인하면 bash 쉘은 Login Shell로 실행된다.
예를 들면,
① 터미널을 통해 SSH를 통해 리눅스 시스템에 접근
② "su -" 명령어를 통해 user를 바꿀 때 이다.
Login Shell(profile) 은 다음과 같은 순서로 명령을 실행한다.
/etc/profile 을 실행/etc/profile 은 /etc/profile.d 안에 있는 스크립트들을 실행$HOME/ .bash_profile 실행 (or ~/.bash_login or ~/.profile)$HOME/ .bash_profile 은 $HOME/ .bashrc 파일 실행$HOME/ .bashrc 는 /etc/bashrc 파일을 실행즉, /etc/profile → /etc/profile.d → $HOME/.bash_profile → $HOME/.bashrc → /etc/bashrc
순으로 읽으며 root 로 로그인 시 /etc/profile 을 먼저 읽고 이후 홈 디렉토리의 실행파일들을 읽는다.
/etc/profile$HOME/.bash_profileHOME 디렉토리에 있으며, 사용자 환경에 맞게 환경변수를 설정한다./etc/profile에서 설정한 전역 변수들을 덮어 사용할 경우도 있다.$HOME/.bashrcNon Login Shell은 login shell로부터 파생된 Shell 이다.
예를 들면,
① ssh로 리눅스 시스템에 접근 후, bash를 실행하는 경우
② GUI 세션에서 터미널을 띄우는 경우 이다.
새로운 환경변수를 설정할 때 non-login shell 경우 .bashrc 파일을 이용해야 한다.
Non Login Shell(rc file) 은 다음과 같은 순서로 명령을 실행한다.
~/.bashrc 를 실행시킨다.~/.bashrc는 /etc/bashrc 를 실행시킨다./etc/bashrc 는 /etc/profile.d 내 스크립트를 실행한다.즉, ~/.bashrc → /etc/bashrc → /etc/profile.d 순으로 읽어나간다.
/etc/bashrc~/.bashrc/etc/profile, ~/.bash_profile, ~/.bashrc, /etc/bashrc
https://linuxism.ustd.ip.or.kr/522
Linux Environment 환경변수
https://seulcode.tistory.com/546
Bash: .profile, .bash_profile, .bashrc
http://dogfeet.github.io/articles/2012/bash-profile.html
[Linux] 환경 변수 & Java,Tomcat 환경 변수 설정 이유
https://it-serial.tistory.com/38
What is the difference between Login and Non-Login Shell
https://tecadmin.net/difference-between-login-and-non-login-shell/
Configuration file overview
https://sanbo0404.tistory.com/entry/etcbashbashrc-rootbashprofile-의-차이