萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

CentOS Shell 提示符僅顯示 -bash-4.1$ 修正方法

修復新建使用者登入後 Prompt 不顯示 user@host 的問題

原因:家目錄缺少 .bash_profile 或 .bashrc,導致 PS1 環境變數未設定。

解決步驟

  1. 編輯家目錄設定檔:vi ~/.bash_profile (不存在則新建)。
  2. 加入 PS1 設定:
    export PS1='[\u@\h \W]\$ '
    \u=用戶名,\h=主機名,\W=當前目錄 basename。
  3. 立即生效:source ~/.bash_profile。

驗證

終端機提示符即變為熟悉的 user@host ~$ 格式。

補充:亦可編輯 ~/.bashrc,並確保 .bash_profile 中 source 了 .bashrc,以同時支援登入與非登入 Shell。

copyright © 萬盛學電腦網 all rights reserved