Login shell and non-Login shell

You use an interactive shell when you enter commands at the shell prompt; you use a non-interactive shell when you run a shell script.

Whenever you log in, the shell that starts is called a LOGIN SHELL. All other interactive shells are called NON-LOGIN SHELLS

The distinction is important because initialization fi les are processed differently for login shells than for non-login shells.

1. Virtual consoles and terminal windows
When you use a desktop environment, such as Gnome or KDE, there are two ways to get to a shell prompt: you can open a terminal window, or you can change to a virtual console When you use a virtual console — say, by pressing <Ctrl-Alt-F1> — you
are required to log in. When you do, a login shell starts. On the other hand, if you simply open a terminal window, a non-login shell starts (because you did not log in).

2. Starting a new shell
At any time, you can start a new shell by entering its name. For example, say you are using Bash, and you want to try the Tcsh. Just enter the tcshcommand. The new shell is a non-login shell (because you did not log in)

3. Using a remote host
To connect to a remote Unix host, you use the ssh(Secure Shell) program. Once ssh makes the connection for you, you must log in. Doing so starts a login shell.

1. A login shell executes your login file andyour environment file.
2. A non-login shell only executes your environment file

 Thus, your login file should contain commands to (1) create or modify environment variables, and (2) perform all one-time actions.

As we discussed earlier in the chapter, the environment is automatically inherited by all child processes, including new shells. Thus, you only need to set environment variables (such as PATH) once, in your login file.

posted on 2013-04-02 21:13  siszqsqx  阅读(405)  评论(0编辑  收藏  举报

导航