Shell related 2------ Login shell and non-login shell and the running mode of the shell

In order to clarify this concept, I did a lot of research, and I saw an article that I thought was very good, and left it for my own study and reference.

http://blog.chinaunix.net/uid-29091195-id-3974770.html

 

login shell

(1) When the user logs in, the shell starts after entering the user name and password;

(2) The shell started by the command with the --login parameter: bash --login.

 

non-login shell

After the user logs in, directly run the shell started by the bash command.

 

The main difference between login shell and non-login shell

The main difference for users is that the startup file that is executed when starting the shell is different.

(1) The startup file of the login shell is /etc/profile, ~/.bash_profile

(2) The startup file for non-login shells is ~/.bashrc

 

The running mode of the shell ( interactive shell, non-interactive shell )

(1) Interactive shell

Interactive mode is where the shell waits for your input and executes the commands you submit. This mode is called interactive because the shell interacts with the user. This pattern is also very familiar to most users: login, execute some commands, sign out. When you sign out, the shell also terminates.

 

The interactive mode is further divided into four types: login, non-login, posix and restricted shell.

login

When Bash is activated as a login shell, it reads and executes the following files in turn:
 /etc/ profile, ~/.bash_profile, ~/.bash_login, ~/
.profile Activating Bash with the --noprofile option prevents it from reading any Initialization file, execute ~/.bash_logout file on exit

non-login

When Bash is activated as a non-login shell, it will read and execute ~/.bashrc

posix

When Bash is activated as posix mode, it will first check whether the $ENV variable is defined. If defined, Bash reads and executes the file obtained by expanding the $ENV variable, otherwise it does not execute any initialization files.

restricted shell

When Bash is activated as restricted mode, it behaves the same as other modes except that certain operations are prohibited. Restricted operations are: changing directories, modifying the $SHELL and $PATH variables, running exec, running programs with absolute paths, and Use redirection.

Restricted mode is not included in Bash 1.x.

 

(2) Non-interactive shell

The shell can also run in another mode: non-interactive mode. In this mode, the shell does not interact with you, but instead reads commands stored in files and executes them. When it reaches the end of the file, the shell terminates. This mode is mainly used to run shell scripts. After startup, Bash checks the $BASH_ENV variable, and if defined, executes the command contained in the file specified by the variable.

 

(3) Bash's activation option
   -c string This option indicates that the string contains a command. For example, bash -c ls ~
   -i makes Bash run in interactive mode
   -r makes Bash run in a restricted mode
   --login makes Bash run in a limited way Run as a login shell
   --posix make Bash follow the POSIX standard
   --verbose make Bash display all the input lines it reads
   --help print Bash usage information
   --version print version information
   --noprofile I feel this is for login shells In other words, --norc is for non-login shells

    (Do not read either the system-wide startup file /etc/profile or
 any of the personal initialization files ~/.bash_profile, ~/.bash_login, or ~/.profile. By default, bash reads
these files when it is invoked as a login shell (see INVOCATION below).)
   --norc Activating Bash with the --norc option disables execution of any initialization files

( Do not read and execute the personal initialization file ~/.bashrc if the shell is inter‐
              active. This option is on by default if the shell is invoked as sh.) --rcfile
   file Use --rcfile file to specify the initialization file.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326175289&siteId=291194637