Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the related concepts and configuration methods of Shell

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what the relevant concepts and configuration methods of Shell are. The content of the article is of high quality. Therefore, Xiaobian shares it with you as a reference. I hope that after reading this article, you will have a certain understanding of relevant knowledge.

There are a variety of shells that are used in the process of using Linux, and depending on the startup environment, the Shell reads different configuration files. This article details when these configuration files with different names are read by Shell.

What is Shell?

Shell(Unix Shell) is a command-line interpreter that is the most traditional human-computer interface under Unix operating systems. In Shell, the user can execute a program by typing in the program name, which was originally used by computer users to get the computer to perform tasks. Shells in heavy use today in Linux and Mac include CSH, Bash, ZSH, etc.

The first Unix Shell was sh, written by Ken Thompson of Bell Labs and used since 1971. The default Shell in Linux distributions such as Ubuntu and Red Hat is Bash (Bourne Shell), written by Stephen Bourne of Bell Labs, hence the name. Hartle uses the Z shell, which is a very modern Shell compatible with Bash.

What is Shell Command?

Shell commands are what we often call Linux commands, and these commands can be divided into two categories:

One type is Shell Builtin, which is related to Shell type. For example, Bash has echo, pwd, etc.

One type is PATH software, such as ls, mkdir, etc. under/usr/bin.

Shell programming is a series of Shell (usually Bash) commands written in a file to be executed in batches. This file is the Shell script, which contains the Shell commands to be executed sequentially.

These Shell scripts are generally named *.sh to indicate execution through the Shell. The first line of a Shell script usually contains an interpreter for the current script file, such as #!/ usr/bin/bash means that when the user executes the script, the execution is interpreted in Bash.

What is Terminal?

A Terminal is a computer device or software that accepts keyboard input and transmits it to the computer, and displays character output from the computer via a screen or printer. The earliest terminal was a teletypewriter (TTY), so TTY and Terminal are synonyms. Linux operating systems to date have provided several TTY terminals (accessed by pressing Ctrl+Alt+F1).

The term terminal originally referred to the device at the end of the cable and was named from an electronic point of view. In Linux terminology, TTY is actually an extended streaming device.

In addition to the system kernel, Terminal Emulators can also provide Terminals, which are often referred to as Pseudo-TTY. Terminal simulator is used to provide Terminal is mainly for convenience, usually a terminal simulator can open multiple terminals. For example, Xterm, GNU Screen, SSH, Terminal in GNome, Konsole in KDE, iTerm2 in Mac, etc. are commonly used in X Windows system. This software is part of Terminal Emulator.

What is Console?

Console is usually the Primary Terminal of a device, software, or operating system. Console is called from the physical sense, the terminal directly connected to the device is called Console. For example, Linux TTY, Chrome console, switch management terminal.

What is Interactive Shell?

Interactive shell and login shell refer to the running state of the Shell. There may be multiple shells running in each operating system, and these shells may be in any of the following running states.

An interactive shell is a Shell that allows users to interact with each other via a keyboard. The CLI we are using is an interactive Shell.

A non-interactive shell is a script that is executed automatically, usually without asking for user input, and the output is typically stored in a log file. For example, the script timed by crontab runs in a non-interactive Shell in the article Update Wallpapers with Cron Timed Tasks.

What is a login Shell?

Login Shell means that the Shell is used for user login when it is run, for example, the Shell in TTY is running in the state of login Shell.

Non-login shells are those that start when the user is logged in. Auto-executed shells are also non-login shells, and their execution is usually independent of user login.

Shell configuration file

A Shell configuration file is actually a special Shell script, but it's not named.sh. Shell commands in the configuration file are selectively executed when the Shell is started. These commands are generally used to configure the working environment under the current Shell, usually including some aliases, PATH, editor (EDITOR) and other configurations.

Shell profiles can be divided into system-level profiles and user-level profiles. Each Shell has a user-level profile and a corresponding system-level profile.

System-level configuration files are located under/etc and apply to all users. For example,/etc/profile,/etc/bashrc.

User-level profiles are located in the user directory ~, usually with an additional. to hide it. For example ~/.profile,~/.bashrc.

At Shell startup, system-level profiles (if any) are executed first, followed by user-level profiles. This means that ~/.bashrc overrides/etc/bashrc.

Login Shell Profile

The login Shell reads login-related configuration files, which can generally be divided into three categories:

.profile Configure login shell behavior. Read when started as a login Shell.. login Read at login.. logout Read when logout.. profile is the configuration file for/bin/sh. Bash is compatible with sh, so Bash reads/etc/profile and ~/.profile when it is used as a login Shell (almost all shells do this). login is the configuration file that the login Shell reads after the user logs in. Both csh and tcsh read it. logout is the configuration file that the login Shell reads when the user logs out, and csh and tcsh both read it. Each Shell, while compatible with the above profiles, also has a number of proprietary profiles. For example, Bash: .bash_profile is Bash's private login Shell configuration file. bash_login is the configuration file that Bash reads after the user logs in as a login Shell. bash_logout is the configuration file that Bash reads when a user logs out as a login Shell. For example, Zsh's.zprofile, .zlogout, .zlogin, etc., see https://wiki.archlinux.org/index.php/zsh

Interactive Shell Profile

There are configuration files that are only read by interactive shells, including.zshrc,.bashrc, etc.

Where.bashrc is read only by interactive, non-login Bash. Therefore, it is common to call ~/.bashrc in.bash_profile to make Bash read ~/.bashrc when it is used as a login Shell:

[[ -r ~/.bashrc ]] && . ~/.bashrc

.zshrc will be read by any interactive Z Shell unless the-f parameter is set. C Shell, TCShell always reads cshrc, .tcshrc when it starts, regardless of whether the Shell is interactive or logged in.

About Shell related concepts and configuration methods are what to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report