/etc
- 시스템 전역(모든 사용자)에게 적용되는 환경변수 파일이다.
~/
login shell
- 사용자가 로컬 또는 원격 시스템에 로그인 할 때 실행되는 셸
ex : ssh로 접속할때
non login shell
- 터미널 창을 열거나 셸 스크립트를 실행할때 이미 실행 중인 세션 내에서 시작되는 셸
ex : ssh로 접속한 이후 새 셸을 실행할때
/etc/profile
- login shell이기 때문에 모든 사용자가 로그인 할 때 수행된다.
- 시스템 전역에 적용
/etc/bashrc
- non login shell이기 때문에 로그인한 상태에서 새 셸을 열때 실행된다.
- 시스템 전역에 적용
~/.bash_profile
- login shell이고 Bash로 해당하는 사용자가 로그인 하는 시점에 실행된다.
- 특정 사용자에게만 적용
~/.bashrc
- Non login shell이기 때문에 로그인한 상태에서 새 셸을 열때 실행된다.
- 특정 사용자에게만 적용
실행순서
- 각 파일의 제일 아래 쪽에 실행 코드를 추가할 때 적용되는 순서
1) /etc/profile.d/*
2) /etc/profile
3) /etc/bashrc
4) ~/.bashrc
5 ~/.bash_profile
호출순서
- OS는 /etc/profile과 ~/.bash_profile을 순서대로 호출한다.
- OS(LINUX) -> /etc/profile -> /etc/profile.d/*
- OS(LINUX) -> ~/.bash_profile -> ~/.bashrc -> /etc/bashrc
순으로 호출되기 때문에 제일먼저 /etc/profile.d/* 제일 아래쪽에 추가된 실행 코드가 먼저 수행되고
이후 /etc/prfoile -> /etc/bashrc -> ~/.bashrc ~/.bash_profile순으로 추가한 코드가 실행된다.
사용이유
셸에 export로 등록한 환경변수나 alias등은 로그아웃 시 정보를 잃게 되고 이를 영구적으로 저장하기 위해 사용한다.
(물리적으로 RAM에 저장)
참고자료
https://zetawiki.com/wiki/Profile_bashrc_bash_profile_%EC%8B%A4%ED%96%89_%EC%88%9C%EC%84%9C
https://spidyweb.tistory.com/221