/etc/profile 是所有登入型 Shell 的全域啟動腳本,負責設定系統級環境變數、路徑、語系與提示字元。本文條列常見變數用途並提供可直接套用的範例。
| 變數 | 用途 | 典型值 |
|---|---|---|
| SHELL | 預設 Shell 程式 | /bin/bash |
| LANG / LC_* | 語系與地區設定 | zh_TW.UTF-8 / en_US.UTF-8 |
| PATH | 指令搜尋路徑 | /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
| MANPATH | man page 搜尋路徑 | /usr/share/man:/usr/local/share/man |
| INPUTRC | Readline 鍵盤對應檔 | /etc/inputrc |
| BASH_ENV | 非互動式 bash 載入的環境檔 | ~/.bashrc |
| DISPLAY | X Server 連線位址 | :0 (本機), 192.168.1.5:0 (遠端) |
| COLORTERM | 終端機模擬器類型 | gnome-terminal, xterm-256color |
| USER / LOGNAME | 目前登入使用者 | auto-set by login |
| HOME | 使用者家目錄 | /home/user |
| 郵件匣路徑 | /var/spool/mail/user | |
| HOSTNAME | 主機名稱 | `/bin/hostname` 輸出 |
| HISTSIZE | 歷史指令記錄筆數 | 1000 |
# /etc/profile - System wide environment
# 路徑設定
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export MANPATH="/usr/share/man:/usr/local/share/man"
# 語系設定 (可用 locale -a 查詢支援清單)
export LANG="zh_TW.UTF-8"
export LC_COLLATE="C"
# 終端機行寬/高自動偵測
export COLUMNS LINES
# 提示字元格式:[user@host dir]$
export PS1='[\u@\h \W]\$ '
export PS2='> '
# 預設檔案建立權限遮罩
umask 022
# 讓子 Shell 繼承以上變數
export PATH MANPATH LANG LC_COLLATE COLUMNS LINES PS1 PS2
export PATH="$PATH:/opt/myapp/bin"export http_proxy=https://proxy:3128export HISTSIZE=5000 HISTFILESIZE=10000alias ls='ls --color=auto' (建議放在 /etc/bashrc 或 ~/.bashrc)/etc/profile
└─ /etc/profile.d/*.sh (模組化擴充)
└─ ~/.bash_profile
└─ ~/.bashrc
└─ /etc/bashrc
系統級修改請編輯 /etc/profile 或在 /etc/profile.d/ 新增 .sh 檔;使用者層級請改 ~/.bash_profile 或 ~/.bashrc。