Colors

如何讓 bash 預設使用顏色編碼輸出?

  • November 19, 2016

我最近試圖起床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

如果是這樣,請務必查看所有這些(如果存在):

  1. /etc/profile
  2. ~/.bash_profile
  3. ~/.bash_login
  4. ~/.profile

如果輸出ls -l ~/.bashrc包含root所有者/組:

sudo chown $USER:$USER ~/.bashrc

此外,預期使用者權限的644含義是:

ls -l ~/.bashrc

給出以下輸出:

-rw-r--r--

如果不是,請按如下方式更改:

chmod 644 ~/.bashrc

引用自:https://unix.stackexchange.com/questions/324465