`
kiikoo
  • 浏览: 7752 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

linux ssh

阅读更多

Difference between login shell and non-login shell

Understanding the distinction between your shell types, profile files and shell rc files is important because when you apply modifications to your system you need to know where to set variables in order to make sure that they can be initialized as expected.

Let's give a quick answer for this topic which covers the exact difference between the two shells.

When you login your system and see the command line prompt, it's a login shell, and it executes these files in order:

  • /etc/profile
  • ~/.bash_profile
  • ~/.bashrc
  • /etc/bashrc

A non-login shell will only execute the two files in order:

  • /etc/bashrc
  • ~/.bashrc

So what's a non-login shell?
When issuing this command:

$ ssh joseph@howto.admon.org 'uptime'

you will gain a non-login shell at the remote side howto.admon.org. when you type bash after login, your new shell is also a non-login shell.

Now, you may have a clear answer to a common system administration question: How can I properly apply a new system variable like JAVA_HOME?

It's better to set it in /etc/bashrc other than /etc/profile. Addtionally, there're better choice. If you prefer to make your system clean and tidy, it's suggested to create single config files in /etc/profile.d, the point is all these file would be initialized by both login shell and non-login shell:

$ grep profile /etc/profile /etc/bashrc
/etc/profile:# /etc/profile
/etc/profile:for i in /etc/profile.d/*.sh ; do
/etc/bashrc:# Environment stuff goes in /etc/profile
/etc/bashrc:        for i in /etc/profile.d/*.sh; do

NOTE: The suffix of the file name should be ".sh", e.g. /etc/profile.d/java.sh

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics