Login shell or a non-login shell?

reprint:http://www.theunixschool.com/2010/05/login-shell-or-non-login-shell.html

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值