更改 shell 颜色:“未找到 dircolors -b 命令”

更改 shell 颜色:“未找到 dircolors -b 命令”

(前言:我是 Linux 的新手。)

问题

我正在尝试在 bash shell 中更改文件系统的颜色。我已.bashrc根据以下内容更改了我的文件:

http://ubuntuforums.org/showthread.php?t=41538

但是在重新启动 shell 或获取来源时.bashrc我收到错误消息:

dircolors -b : command not found

我做错了什么?

设置及到目前为止

我正在运行全新的 Ubuntu Server 13.04。

.dir_colors我使用以下命令在我的主目录中创建了一个文件:

dircolors -p > ~/.dircolors

然后我将 .bashrc 修改为如下所示:

# enable color support of ls and also add handy aliases
    if [ "$TERM" != "dumb" ]; then
        [ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors"
        [ -e "$DIR_COLORS" ] || DIR_COLORS=""
        eval "`dircolors -b $DIR_COLORS`"
        alias ls='ls --color=auto'
        #alias dir='ls --color=auto --format=vertical'
        #alias vdir='ls --color=auto --format=long'
    fi    

我也force_color_prompt启用了

编辑:打印输出<~/.bashrc grep dircolors | od -t x1

0000000 20 20 20 20 65 76 61 6c 20 22 27 64 69 72 63 6f
0000020 6c 6f 72 73 20 2d 62 20 24 44 49 52 5f 43 4f 4c
0000040 4f 52 53 27 22 0a
0000046

编辑:打印输出whereis dircolors

dircolors: /usr/bin/dircolors /usr/bin/X11/dircolors /usr/share/man/man1/dircolors.1.gz

答案1

我的最终设置。我使用此命令在我的用户目录中创建 dircolors 配置文件。

dircolors -p > ~/.dircolors 

然后我编辑了我的.bashrcif条件与我最终的 if 条件有很大不同,我通过查找找到了正确的位置:

# enable color support of ls and also add handy aliases

然后我将该部分更改为:

# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
    [ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors"
    [ -e "$DIR_COLORS" ] || DIR_COLORS=""
    eval "`dircolors -b $DIR_COLORS`"
    alias ls='ls --color=auto'
    #alias dir='ls --color=auto --format=vertical'
    #alias vdir='ls --color=auto --format=long'
fi

我犯错的关键部分是'在下一行中我使用了单引号而不是反引号(请参阅@steeldriver 评论,我无法将它们打印出来)。

    eval "`dircolors -b $DIR_COLORS`"

相关内容