home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 2.7 C Shell Setup Files Aren't Read When You Want Them to Be? Chapter 2
Logging In
Next: 2.9 Speeding Up Your C Shell with set prompt Test
 

2.8 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 ( 38.4 ) (started from the login shell) or separate shells started by at ( 40.3 ) , rsh ( 1.33 ) , 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 ( 6.8 ) 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 7.9 shows another solution.

- JP


Previous: 2.7 C Shell Setup Files Aren't Read When You Want Them to Be? UNIX Power Tools Next: 2.9 Speeding Up Your C Shell with set prompt Test
2.7 C Shell Setup Files Aren't Read When You Want Them to Be? Book Index 2.9 Speeding Up Your C Shell with set prompt Test

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System