Colors
如何讓 bash 預設使用顏色編碼輸出?
我最近試圖起床
node.js
和跑步。我需要將導出行添加到.bashrc
文件中的步驟之一。這樣做並重新啟動機器後,bash 終端的輸出不再是彩色編碼的。我嘗試使用複制預設值,
cp /etc/skel/.bashrc ~/.bashrc
然後取消註釋該行force_color_prompt=yes
。但是當我重新啟動機器時,輸出仍然是黑白的。如果我執行
source .bashrc
或. .bashrc
輸出按預期工作(它是彩色編碼的)。但這不是登錄時的預設行為。如何在登錄時將 bash 設置為預設使用顏色編碼的輸出?
您可能
.profile
沒有載入.bashrc
文件。cat ~/.profile
應該看起來有點類似於:
# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/bash/examples/startup-files for examples. # the files are located in the bash-doc package. # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi # set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi
但是還有很多其他地方需要檢查:
你真的在跑步嗎
bash
:ls -l $SHELL
如果是這樣,請務必查看所有這些(如果存在):
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
如果輸出
ls -l ~/.bashrc
包含root
所有者/組:sudo chown $USER:$USER ~/.bashrc
此外,預期使用者權限的
644
含義是:ls -l ~/.bashrc
給出以下輸出:
-rw-r--r--
如果不是,請按如下方式更改:
chmod 644 ~/.bashrc