본문 바로가기
Linux&Ubuntu/서버

[linux] profile, bashrc ,bash_profile 차이 및 순서

by Vittorio_Lee 2021. 10. 31.
728x90
반응형
SMALL

실행순서

1) profile -> 2 ) bash_profile  -> 3) bashrc

 

1) /etc/profile

login shell을 bash shell 로 실행하는 모든 user에게 적용.

직접 편집하는 것보다 /etc/profile.d에 shell script 작성
history시간등록 등~

vim /etc/profile

해당파일 안의 shell script

if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`/usr/bin/id -u`
        UID=`/usr/bin/id -ru`
    fi
    USER="`/usr/bin/id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi
done

2) .bash_profile 

login 쉘을 배시쉘로 실행하는 모든 user에게 적용
bash shell을 실행하는 모든 시스템에 적용할 함수나 별칭(aliases) 추가

alias 'vi'='vim' 등과같은 ~

#vim /root/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

3)/etc/bashrc

 User에게 적용할 함수나 별칭 추가

 

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    screen*)
      if [ -e /etc/sysconfig/bash-prompt-screen ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
      else
          PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    *)
      [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
      ;;
    esac
  fi

 

728x90
반응형
LIST