免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6784 | 回复: 14
打印 上一主题 下一主题

~/.profile和~/.bashrc到底有什么区别? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-12 15:31 |只看该作者 |倒序浏览
老实说,我确实没看懂man bash中的这句话“When  an  interactive  shell  that is not a login shell is started, bash reads and executes commands from ~/.bashrc”

论坛徽章:
0
2 [报告]
发表于 2009-03-12 15:35 |只看该作者
原帖由 sdemon915 于 2009-3-12 15:31 发表
老实说,我确实没看懂man bash中的这句话“When  an  interactive  shell  that is not a login shell is started, bash reads and executes commands from ~/.bashrc”

我是新手,多看,少想,不钻。

论坛徽章:
0
3 [报告]
发表于 2009-03-12 15:36 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
4 [报告]
发表于 2009-03-12 15:37 |只看该作者
原帖由 sdemon915 于 2009-3-12 15:31 发表
老实说,我确实没看懂man bash中的这句话“When  an  interactive  shell  that is not a login shell is started, bash reads and executes commands from ~/.bashrc”



你去看一下/etc/下的profile和bashrc这两个文件中的shell就应该明白了


我想知道一个问题~/.profile文件是做什么呢?老是听有人说!

论坛徽章:
0
5 [报告]
发表于 2009-03-12 15:41 |只看该作者
/etc/profile文件是一个系统级初始化文件,在用户登陆时执行指定任务。它可以被系统上所有用户使用。

论坛徽章:
0
6 [报告]
发表于 2009-03-12 15:43 |只看该作者
原帖由 linuxboy823 于 2009-3-12 15:37 发表



你去看一下/etc/下的profile和bashrc这两个文件中的shell就应该明白了


我想知道一个问题~/.profile文件是做什么呢?老是听有人说!

是不是这样,root登陆后会使用~/.profile和~/.bashrc这两个文件
而不登陆的root仅仅使用~/.bashrc这个问题捏?

论坛徽章:
0
7 [报告]
发表于 2009-03-12 15:48 |只看该作者
如果用户的主目录下找到.bash_profile 那么在执行完/etc/profile后,将执行这个文件,如果.bash_profile找不到,找另一个文件.bash_login 如果.bash_login也不存在,再找用户目录下的.profile并执行,只对这三个文件中的一个进行执行操作。
[root@localhost ~]# cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

论坛徽章:
0
8 [报告]
发表于 2009-03-12 17:22 |只看该作者
谁还是翻译一下LZ的那句话比较实在

论坛徽章:
0
9 [报告]
发表于 2009-03-12 17:56 |只看该作者
在普通交互shell(非login shell)启动时,bash获取并执行~/.bashrc中的命令行。

印象中login shell是指登录服务器启动的shell,还有su -l启动的shell等等,就是带“login”参数的。不确定,再回去找找看……

论坛徽章:
0
10 [报告]
发表于 2009-03-12 20:10 |只看该作者
你可以加一句到.bashrc
echo "yes"
然后
1)你logout
2)login,屏幕上会出现"yes",因为.profile在login时会被执行,而.profile里一般都有:
    if [ -f ~/.bashrc ]; then
        .     ~/.bashrc
    fi
3)在已经登录的情况下,你再输入bash命令,进入一个交互式的bash(非login程序启动的),这时屏幕上又会有"yes",因为.bashrc会被bash执行,而.profile不被执行.

以上供参考
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP