JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Differences between Login and Non-Login Shells

Author:JIYIK Last Updated:2025/04/05 Views:

This article explains the difference between login shells and non-login shells in UNIX-based systems.

What is Shell in UNIX based systems

The shell in UNIX based systems is the interface between the user and the kernel of the operating system. It takes input from the user and sends it to the kernel and takes the result from the kernel to the user.

There are two types of shells, login shells and non-login shells.

Each shell executes a series of startup scripts after startup to set up the environment. These scripts have different purposes, and they all affect the environment.

Subsequent scripts can overwrite values ​​set by earlier scripts.

What is a Login Shell in UNIX based systems

A login shell is the first process started after a successful login /bin/loginby reading /etc/passwdthe .login file. A login shell executes under your user ID.

A login shell is executed when you log in using a terminal, switch to another user, or use SSH.

Once a login shell starts, it executes a set of startup scripts to set up the shell environment. The following scripts are executed.

The following command is used to indicate whether the shell is a login shell.

echo  $0

Getting -bashor -suas output indicates that the shell is a login shell. Note -the symbol before the output.

In the following figure, echo $0the output of the command bashhas a in front of -. It indicates that the shell is a login shell.

Login shell

What is a non-login shell in UNIX based systems

A login shell starts a non-login shell. This can be a shell started as a process that is not logged in, or a shell started from another shell. The process starts a non-login shell using the name of the shell executable file.

Running a bash shell as a non-login shell executes the following script.

To determine if your shell is a non-login shell, run the following command.

echo $0

If the output is bashor suwithout a preceding -_, the shell is a non-login shell.

We execute the command in the figure below echo $0, and the output shows bashthe previous one -. This means we are using a login shell.

To start a non-login shell, we enter the name of the shell executable, in our case bash. We execute echo $0the command again to see what type of shell the newly started shell is; echothe output of the command is bash. -This means that the new shell is a non-login shell.

Non-login shell

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

How to decompress x.tar.xz format files under Linux

Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM

A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr

Summary of vim common commands

Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM

In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme

Detailed explanation of command return value $? in Linux

Publish Date:2025/04/08 Views:58 Category:OPERATING SYSTEM

? is a special variable. This variable represents the return value of the previous command. That is to say, when we run certain commands, these commands will return a code after running. Generally, if the command is successfully run, the re

Common judgment formulas for Linux script shell

Publish Date:2025/04/08 Views:159 Category:OPERATING SYSTEM

In shell script programming, predicates are often used. There are two ways to use predicates, one is to use test, and the other is to use []. Let's take a look at how to use these two methods through two simple examples. Example 1 # test –

How to use the Linux file remote copy command scp

Publish Date:2025/04/08 Views:151 Category:OPERATING SYSTEM

Scp copies files between two hosts over the network, and the data is encrypted during transmission. Its underlying layer uses ssh for data transmission. And it has the same authentication mechanism and the same security level as ssh. When u

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial