본문 바로가기

Ubuntu

profile.d

/etc/profile은 “로그인(login) 셸”이 시작될 때(주로 bash, sh 계열) 시스템 전체에 공통으로 적용할 환경 설정을 로드하는 스크립트이다.

 

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "${PS1-}" ]; then
  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "$(id -u)" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi"

 

마지막 if 문을 보면, 

  • etc/profile 하나에 모든 설정을 넣지 말고,
  • 기능별로 /etc/profile.d/ 아래에 스크립트를 쪼개서 관리하게 하려는 구조입니다.
    • 예: locale.sh, proxy.sh, cuda.sh, intel-oneapi.sh 같은 식

각 구문 의미

  • -d /etc/profile.d : 디렉터리 존재 확인
  • for i in /etc/profile.d/*.sh : .sh로 끝나는 파일을 순회
  • -r $i : 해당 파일이 “읽기 가능”하면
  • . $i : 파일 내용을 현재 셸에서 실행(환경 변수 export 등이 현재 셸에 반영됨)
  • unset i : 루프 변수 i를 지워서 환경을 더럽히지 않음(작은 깔끔함)

'Ubuntu' 카테고리의 다른 글

검색 기본 순위  (0) 2026.01.07
Chrony  (0) 2025.10.06
시간세팅  (0) 2025.05.08
Linux Manual  (0) 2025.05.03
make log 파일 만들기  (0) 2025.05.01