Monday, May 10, 2010

Login shell or a non-login shell?



 Shells in UNIX are classified into two categories:
  • Login Shell
  • Sub shell (Non-Login shell)
    Login shell is a shell where the user reaches on trying to login to his account. This login shell, ksh or bash or tcsh or sh, is defined for the user at the time of user account creation. However, the login shell of an user can always be changed by the root user. 

   Sub shell or a non-login is a shell which is invoked from the login shell or from a different sub shell by just typing the name of the shell. In fact, whenever a shell script is run, a sub-shell is opened internally and the script is run from the sub-shell.

1. How to go to a sub-shell?
  
  Simple, from the current shell, if you want to go to a k-shell, type 'ksh' at the prompt.
#ksh
#
   In the same way, one can switch to any shell by tying the name of the shell at the prompt. In other words, any shell opened from the login shell in the above manner is a sub-shell.

2. How to find out whether the shell is a login-shell or a non-login shell?

   Two environment variables are available to find or identify whether a shell is login or sub-shell.
  • $SHELL - This always tells the login shell.
  • $0        - This always tells the current shell.
   i) Login Shell: Assuming the user is currently in his login-shell which is tcsh:
#echo $SHELL
tcsh
#echo $0
tcsh
#
    In this case, both the variables are showing the same value. It is because the login shell and current shell are same in this case.

  ii) Non-Login shell:
#echo $SHELL
tcsh
#ksh
#echo $SHELL
tcsh
#echo $0
ksh
#
   As shown above, the user initially is in login shell tcsh and then switches to ksh. On switching to ksh, the $0 shows ksh however the SHELL variable still shows tcsh.



Related Posts Plugin for WordPress, Blogger...

No comments:

Post a Comment