.profile, .bashrc 차이 및 실행순서

.bash_profile, .bashrc 차이

둘의 차이는 실행이 되는 시점이 다르다.

.bash_profile 의 경우, 로그인 되는시점에 실행
.bashrc 의 경우, 이미 로그인한 시점에서 새로운 콘솔창(세션)을 열때 실행.


리눅스의 bash의 .bash_profile, .bashrc 실행순서

OS에서는 /etc/profile, .bash_profile or .profile을 실행하고, 각 파일 내부에서 다른 파일을 실행한다.

실행순서(내부 shell script포함) : /etc/profile -> /etc/profile.d/*.sh -> .bash_profile OR .profile -> .bashrc -> /etc/bashrc

1. /etc/profile

해당파일 안의 shell script
for i in /etc/profile.d/*.sh ; do

    if [ -r "$i" ]; then

        if [ "${-#*i}" != "$-" ]; then

            . "$i"

        else

            . "$i" >/dev/null 2>&1

        fi

    fi

done


2. .bash_profile OR .profile (.bash_profile 이 없으면 .profile을 실행. .bash_profile 이 1순위이고, 우선순위에 따라 1개만 실행된다.)

해당 파일안의 shell script
if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi