start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 51.8 Type Bang Splat.  Don't Forget the Rabbit Ears Chapter 51
Miscellaneous Useful Programs and Curiosities
Next: 51.10 The date Command
 

51.9 Making a "Login" Shell

When you log in to most UNIX systems, your shell is a login shell . When a shell is a login shell, it acts differently. For example, the shell reads a special setup file ( 2.2 ) like .profile or .login . UNIX "knows" how to tell the shells to be login shells. If you type the shell's name (like sh or /bin/csh ) at a prompt, that will not start a login shell.

Sometimes, when you're testing an account or using a window system, you want to start a login shell without logging in. UNIX shells act like login shells when they are executed with a name that starts with a dash ( - ). [1] The easiest way to do this, which wastes a lot of disk space (and may not work on your system anyway if the shells are read-protected), is to make your own copy of the shell and name it starting with a dash:

[1] bash also has a command-line option, -login , that makes it act like a login shell.

 
bin
  
./-
 
 $ 

cd $HOME/bin

 $ 

cp /bin/csh ./-csh

It's better to make a symbolic link ( 18.4 ) to the shell:

$ 

cd $HOME/bin

 $ 

ln -s /bin/csh ./-csh

(Or, if your own bin subdirectory is on the same filesystem as /bin , you can use a hard link ( 18.4 ) .) A third way is to write a little C program ( 52.8 ) that runs the actual shell but tells the shell that its name starts with a dash. This is how the UNIX login process does it:

main() {     execl("/bin/csh", "-csh", 0); }

No matter which way you choose, you can execute your new shell by typing its name:

$ 

-csh

    
...normal C shell login process...
 % 
...run whatever commands you want...
 % 

logout

 $ 
...back to original shell

Article 2.16 shows how this can be used to change your normal login shell.

- JP


Previous: 51.8 Type Bang Splat.  Don't Forget the Rabbit Ears UNIX Power Tools Next: 51.10 The date Command
51.8 Type Bang Splat. Don't Forget the Rabbit Ears Book Index 51.10 The date Command

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