Identifying Login Shells
When you first log in to a UNIX system from a terminal, the system usually starts a login shell. This is where you want to do general setup - initialize your terminal, set environment variables, and so on. Here the C shell reads your login file, and Bourne-type shells read profile (bash can read others).
Other shells are either subshells () (started from the login shell) or separate shells started by at (), rsh (), etc. These shells don't read login or profile.
To make it possible to find out which you've got, add the line below to the top of your login or profile file: The line sets a shell variable () named loginshell:
set loginshell=yes csh loginshell=yes sh-type shells
Now wherever you need to know the type of shell, use tests like:
if $? if [...] |
if ($?loginshell) csh if [ -n "$loginshell" ] sh-type shells |
---|
This works because only login shells read login or profile. The loginshell variable will be defined only in login shells.
Article shows another solution.
- JP