LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 950|回复: 11

诚惶诚恐:弱弱滴问个老问题,bash如何显示文件颜色?

[复制链接]
发表于 2005-1-10 15:15:34 | 显示全部楼层 |阅读模式
我的做法:

1 dircolors -p > /etc/dircolors
2 建立/etc/profile文件

# /etc/profile开始
pathman () {
        if ! echo $PATH | /bin/egrep -q "(^|: )$1($|: )" ; then
                if [ "$2" = "last" ] ; then
                        PATH=$PATH1
                else
                        PATH=$1PATH
                fi
        fi
}

# 添加到标准路经
if [ $(id -u) = 0 ] ; then
        if [ -d "/usr/local/sbin" ] ; then
                pathman /usr/local/sbin last
        fi
fi

if [ $(id -u) != 0 ] ; then
        if [ -d "/usr/local/bin" ] ; then
                pathman /usr/local/bin last
        fi
fi

if [ -d "/usr/X11R6/bin" ] ; then
        pathman /usr/X11R6/bin last
fi

# 设定一些环境变量
HISTSIZE=1000
PS1="[\u@\h \w]\\$ "

# 设定 INPUTRC 变量
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
        INPUTRC=/etc/inputrc
fi

# 设置 /bin/ls 支持颜色,其别名放在 /etc/bashrc中
if [ -f "/etc/dircolors" ] ; then
        eval $(dircolors -b /etc/dircolors)

        if [ -f "$HOME/.dircolors" ] ; then
                eval $(dircolors -b $HOME/.dircolors)
        fi
fi

export PATH HISTSIZE PS1 LS_COLORS INPUTRC
# /etc/profile 结束


3 建立/etc/bashrc文件
# /etc/bashrc开始
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>

# 文件中设置系统全局别名(aliases)和函数

# 系统全局变量和初始程序包含于 /etc/profile。  个人
# 的环境变量和初始程序应该在~/.bash_profile中  个人的别名和
# 函数设置应该放在 ~/.bashrc里面。

# 作为缺省使用 umask 来获取设置
# 对于非互动和非启动shell都是这样。
if [ "$(id -gn)" = "$(id -un)" -a $(id -u) -gt 99 ] ; then
        umask 002
else
        umask 022
fi

# 设置 /bin/ls 为有颜色的列表。配合 /etc/profile里面的设置一起起作用。
alias ls='ls --color=auto'
eval `dircolors -b`                        #这行是我加的,用的是反单引号
# /etc/bashrc结束

:beat  :beat  :beat
上述做法不成功,logout、reboot都不行,我又把他们都cp 到了root目录下,.profile .bashrc .dircolors,仍然不行,我甚至把RH9 /etc目录下的profile bashrc DIR_COLORS也cp到我的LFS的 /etc目录下,还是失败。
#echo $TERM
#linux
#echo LS_COLORS
...........(一大堆的值)

我还有什么没做?或者我做错了什么?
发表于 2005-1-10 15:54:57 | 显示全部楼层
alias ls='ls --color=auto'
将上面这行加入profile就可以了。
 楼主| 发表于 2005-1-10 17:00:25 | 显示全部楼层
真是太感谢了,原来我加错地方了。
发表于 2005-1-10 21:30:31 | 显示全部楼层
BLFS文档里有啊。
 楼主| 发表于 2005-1-11 09:33:08 | 显示全部楼层
我就是按照BLFS文档做的啊,文档里的这句话  alias ls='ls --color=auto' 是加在 /etc/bashrc 里的,在我的机子里没有用,我是加在 ~/.bash_profile,就这一句,就好了
发表于 2005-1-11 18:26:20 | 显示全部楼层
发重复了~~
发表于 2005-1-11 18:27:46 | 显示全部楼层
当你开机登录的时候,bash是读/etc/profile文件,当你打开一个比如xterm或者su等其他操作的时候,bash是读bashrc文件


1:
mkdir /etc/profile.d/

2:
vi /etc/profile
#在里面加入如下代码:
#for scripts in /etc/profile.d/*.sh;do
# if [ -x $scripts ];then
#          sh $scripts
#   fi
# done

3:
vi /etc/profile.d/dircolors.sh
#在里面加入如下代码:
#if [ -f "/etc/dircolors" ] ; then
#        eval $(dircolors -b /etc/dircolors)

#        if [ -f "$HOME/.dircolors" ] ; then
#                eval $(dircolors -b $HOME/.dircolors)
#        fi
#fi
#alias ls='ls --color=auto'

4.
dircolors -p > /etc/dircolors
发表于 2005-1-11 20:10:32 | 显示全部楼层
新的profile里本身就有,只是改改属性

chmod +x /etc/profile.d/*
发表于 2005-1-11 21:43:22 | 显示全部楼层
当存在~/.bashrc和~/.bash_profile时,它们总比/etc/bashrc和/etc/profile优先,
如果要/etc/bashrc或/etc/profile生效的话,只要在~/.bashrc里写上:
if [ -f "/etc/bashrc" ] ; then
        source /etc/bashrc
fi
在~/.bash_profile里写上:
if [ -f "$HOME/.bashrc" ] ; then
        source $HOME/.bashrc
fi

就行了。不会出现/etc/bashrc写了白写的情况。
 楼主| 发表于 2005-1-12 09:54:33 | 显示全部楼层
多谢大家的热心,我已经明白了。
楼上的,你这么写,~/.bashrc和~/.bash_profile岂不是白费了?哈哈。

现在有些郁闷,当你弄某件事的时候,怎么都得不到结果。过了n分钟,上个WC,抽根烟,感觉什么都没干,结果却出来了。我倒!没学到东西,反而更糊涂了~~~,不知道是命苦还是命好???
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表