LINUX下用户登录脚本

转载自:http://hi.baidu.com/shiqiang_hx/blog/item/aab77006e673217a030881cc.html


查看bash的手册页(man bash),发现以下内容:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists.   After reading that file, it looks for ~/.bash_profile,   ~/.bash_login,   and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.   The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file   exists. This   may   be   inhibited   by using the --norc option.   The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

当Bash以交互方式被调用或以带--login参数的非交互方式被调用时,它首先查找/etc/profile文件,如果文件存在就读取并执行该文件中的命令,然后依次查找“~/.bash_profile”,“~/.bash_login”和“~/.profile”这三个文件,然后执行第一个存在并且可读取的文件。使用“--noprofile”选项可以使shell在启动时不执行这些文件。

当退出一个登录Shell时,bash会查找“~/.bash_logout”文件,如果存在就读取并执行它。

当启动一个非登录交换式Shell时,bash尝试~/.bashrc文件,如果存在就读取并执行它。使用“--norc”选项可以不执行它。使用“--rcfile 文件”选项将强制bash读取并执行指定的文件来代替“~/.bashrc”。

因此,如果需要在用户一登录时就执行某些程序(如zhcon)就可以加到以上文件中。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值