Come to learn the construction skills of the Shell environment in the Linux system

What is the shell environment? The shell will store a lot of information in the session, and this information is the shell environment. Linnx command program outputs the corresponding configuration data of the machine by obtaining the data in the shell environment (the data here is usually referred to as environment variables) < p > < / P > < p > linux environment variable < / P > < p > linux shell environment stores two basic types of data: environment variable and shell variable. Of course, in addition to variables, the shell also stores some programmable data, namely aliases and shell functions < p > how to view environment variables < p > we can use bash command set or printenv command program to view environment variables < p > the difference between them is that the set command displays not only shell data, but also the list of environment variables, while the printenv command only displays the list of environment variables < p > in view of the long list of environment variables, we can pass the output of each command to less through the pipe symbol to output the list, for example: < / P > < p > / / execute the command < / P > < p >[ [email protected] ~]$printenv | less < / P > < p > / / output content: list of environment variables and their values < / P > < p > KDE_ MULTIHEAD=false

SSH_ AGENT_ PID=6666

HOSTNAME= linuxprobe

GPG_ AGENT_ INFO=/tmp/gpg-PdOt7g/S.gpg-agent:6689:1

SHELL=/bin/bash

TERM=xterm

XDG_ MENU_ PREFIX=kde-

HISTSIZE=1000

XDG_ SESSION_ COOKIE=6d7b05c65846c3eaf3101b0046bd2b00-1208521990.996705

-1177056199

GTK2_ RC_ FILES=/etc/gtk-2.0/gtkrc:/home/me/. gtkrc-2.0:/home/me/. kde/sh

are/config/gtkrc-2.0

GTK_ RC_ FILES=/etc/gtk/gtkrc:/home/me/. gtkrc:/home/me/. kde/share/confi

g/gtkrc

GS_ LIB=/home/me/. fonts

WINDOWID=29360136

QTDIR=/usr/lib/qt-3.3

QTINC=/usr/lib/qt-3.3/include

KDE_ FULL_ SESSION=true

USER=test

LS_ COLORS=no=00:fi=00:di=00; 34_ln=00; 36_pi=40; 33_so=00; 35_bd=40; 33; 01

:cd=40; 33; 01_or=01; 05; 37; 41_mi=01; 05; 37; 41_ex=00; 32:*. cmd=00; 32:*. Exe: < / P > < p > < / P > < p > / / printenv command can also output the value of specific variable – user: < / P > < p >[ [email protected] ~]$printenv user < / P > < p > test < / P > < p > < / P > < p > variable < / P > < p > content < / P > < p > display < / P > < p > if you are running a graphical interface environment, this variable is the name of your display. Usually, it is “0”, which means the first display generated by X < p > editor < / P > < p > name of text editor < / P > < p > shell < / P > < p > name of shell program < / P > < p > Home < / P > < p > user home directory < / P > < p > Lang < / P > < p > defines character set and language coding method < / P > < p > old_ PWD < / P > < p > the name of the previous working directory < / P > < p > page < / P > < p > output program. This is often set to / usr / bin / less < / P > < p > Path < / P > < p > a list of directories separated by colons. When you enter the executable name, you will search this list of directories

PS1

Prompt String 1. This defines the contents of your shell prompt. Then we can see that this variable content can comprehensively customize < / P > < p > PWD < / P > < p > current working directory < / P > < p > term < / P > < p > terminal type name. UNIX like systems support many terminal protocols; The protocol variable used by your emulator < p > TZ < / P > < p > specify your time zone. Most UNIX like systems maintain the computer’s internal clock according to coordinated time (UTC), and then apply a deviation specified by this variable to display the local time < p > User < / P > < p > your user name < / P > < p > < / P > < p > < / P > < p > establish Linux shell environment < / P > < p > < / P > < p > whenever we log in to the system, bash program will start automatically and read a series of configuration scripts, which are called startup files. These startup files define the default shell environment that can be shared by all users < p > the startup file located in the home directory defines the user’s personal shell environment < p > the exact start order depends on the shell session type pattern. There are two shell session type modes: one is login shell session mode and the other is non login shell session mode < p > in the login shell session mode, the user will be prompted to enter the user name and password; The non login shell session mode usually appears when starting a terminal session under the GUI < p > startup file content in login shell session mode: < / P > < p > file < / P > < p > content < / P > < p > / etc / profile < / P > < p > global configuration script for all users < / P > < p > ?/. bash_ Profile < / P > < p > user’s personal startup file. It can be used to modify the setting < / P > < p > in the global configuration script ?/. bash_ Login < / P > < p > if file ?/. bash_ If the profile is not found, bash will try to read the script < / P > < p > ?/. Profile < / P > < p > if file ?/. bash_ Profile or file ?/. bash_ If login is not found, bash will try to read the file < p > < / P > < p > startup file content in non login shell session mode: < / P > < p > file < / P > < p > content < / P > < p > / etc / bash Bashrc < / P > < p > global profile for all users < / P > < p > ?/. Bashrc < / P > < p > user’s personal startup file. It can be used to modify the settings in the global configuration script < / P > < p > < / P > < p > modify the Linux shell environment < / P > < p > according to the usual operation idea, add a directory to the path variable or define a new environment variable, and then store these changes in the bash_ In the profile file; Other changes need to be stored in Bashrc file < p > except that the system administrator has the right to modify the default settings of all users in the system, other users can only modify the files in their personal home directory < p > we use a program called text editor to edit (or read and write) the shell startup file and other configuration files. A text editor is a program similar to a word processor that allows editing on the screen using a moving cursor. But the difference is that text editors not only support plain text, but also often contain features designed to facilitate programming. It can be seen that the text editor is one of the important tools used by developers to write code and system administrators to manage and control the configuration files of the system < p > text editors are usually divided into two basic types: graphical and non graphical (text-based) editors < p > some typical graphical editors are gnome and KDE. Gnome editor comes with GEDIT editor, which is usually called “text editor” in Gnome menu. KDE comes with three editors: kedit, kwrite and Kate < p > then the text-based editors are nano, VI and Emacs The < p > nano editor is an easy-to-use editor. VI editor (currently replaced by VIM (“VI improved”) is a traditional editor similar to UNIX operating system. Emacs editor is a huge, multi-purpose programming environment that can do any operation < p > for any type of text editor, you can enter the name of the editor and the file name you want to edit on the command line to perform text editing. In this article, we learned the basic skills of editing configuration files with a text editor < p > this article mainly discusses some basic knowledge and basic operation skills of Linux shell environment. In the process of writing this article, I also referred to this book, which is based on red hat 8. The content is very close to practice and has great theoretical guidance and practical value