Pipe and job control, shell variables, environment variable profiles

Source: Internet
Author: User

Pipe character

It is used for the output of the previous instruction as input to the latter instruction.

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/16/1a4adbd82674ccd735f9b4748eaac9ac.png-wh_500x0-wm_3 -wmp_4-s_2715965200.png "title=" 1.png "alt=" 1a4adbd82674ccd735f9b4748eaac9ac.png-wh_ "/>




Job Control

When you run the process, you can pause it (press CTRL + Z), then use the FG (foreground) command to restore it, or use the BG (background) command to make it run in the background. In addition, you can also make it stop (press CTRL + C key combination).


Example: Using the VI command to edit 1.txt, casually write some content, after pressing the ESC key, use CTRL + Z key combination to pause the task, as follows:

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/16/e49a05fc1bdf47b6ab6cfa454b2d6cdb.png-wh_500x0-wm_3 -wmp_4-s_197803271.png "title=" 2.png "alt=" E49a05fc1bdf47b6ab6cfa454b2d6cdb.png-wh_ "/>

At this point the VI 1.txt has stopped, and then use the FG command to restore it, and then into the VI window just now. Pause it again and enter jobs to see the tasks that are paused or run in the background as follows:

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/16/911ac8ed54a1ad6531bf0dea221f6fc6.png-wh_500x0-wm_3 -wmp_4-s_683154250.png "title=" 3.png "alt=" 911ac8ed54a1ad6531bf0dea221f6fc6.png-wh_ "/>


If you want to put the paused task back in the background, use the BG command as follows:

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/16/7c52408d6d3082b39789df20bd632321.png-wh_500x0-wm_3 -wmp_4-s_215871839.png "title=" 4.png "alt=" 7c52408d6d3082b39789df20bd632321.png-wh_ "/>

Vmstat 1 is a command used to observe the state of a system. Multiple suspended tasks will be numbered, two tasks can be seen using the jobs command, and will need to be numbered after using the BG or FG commands. Use the command BG 2 to put the 2nd paused task back in the background (you need to append the symbol & to the command, with a space in the middle).







Shell variables

The ENV command lists all system variables that are preset by the system.

650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/89c8bf1bd9ba69501b7753120dfdb0ca.png "title=" Clipboard (6). png "alt=" 89c8bf1bd9ba69501b7753120dfdb0ca.png "width=" 650 "style=" padding:0px;margin:0px; Vertical-align:top;border:none; "/>


Common environment variables

Hostname indicates the name of the host

Shell represents the shell type of the current user

Histsize indicates the number of historical records

Mail indicates the current user's message store directory

PATH this variable determines to which directories the shell will look for commands or programs

PWD indicates the current directory

LANG This is a language-related environment variable that can be modified by a multi-lingual environment

Home indicates the home directory of the current user

LOGNAME indicates the login name of the current user



The variables shown in env are only environment variables, and set can also enter environment variables. The SET command can display not only the system preset variables, but also user-defined variables.

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/16/1a84437a3d6320fc77f8e1e5e31dcd83.png-wh_500x0-wm_3 -wmp_4-s_3588737232.png "title=" 5.png "alt=" 1a84437a3d6320fc77f8e1e5e31dcd83.png-wh_ "/>

This myname custom variable takes effect only in the current shell.


Keep variables in effect

1. Allow all users in the system to log in and use the variable. How to do this: add the export Myname=huang to the last line of the/etc/profile file, and then run Source/etc/profile to take effect.

2. Allow only the current user to use the variable. How to do this: add Expor Myname=huang to the last line of the. bashrc file in the user's home directory, and then run the source. BASHRC will take effect.

(The purpose of the source command is to refresh the configuration that is currently set, i.e. it can be used without rebooting)


Rules for custom variables under Linux:

The format is a=b, where a is the variable name, b is the variable content, and there is no space on either side of the equal sign.

Variable names can only consist of letters, numbers, and underscores, and cannot start with a number

A single quotation mark is required when the variable name content has special characters, such as spaces.

[Email protected] ~]# MYNAME=CCJ

-bash:da: Command not found

[Email protected] ~]# myname= ' CCJ '

[Email protected] ~]# echo $myname

Ccj


Double quotation marks if the contents of the variable itself have single quotes

[Email protected] ~]# myname= ' CCJ '

> ^c

[Email protected] ~]# myname= "CC ' J"

[Email protected] ~]# echo $myname

CC ' J


If you need to use a different command in the contents of the variable, you need to use single quotation marks

[Email protected] ~]# myname= ' pwd '

[Email protected] ~]# echo $myname

Pwd

[Email protected] ~]# myname= "pwd"

[Email protected] ~]# echo $myname

Pwd

[Email protected] ~]# myname=pwd #无引号

[Email protected] ~]# echo $myname

Pwd

[Email protected] ~]# myname= ' pwd ' #反引号

[Email protected] ~]# echo $myname

/root


Double quotation marks are required if the contents of the variable need to accumulate additional content

[Email protected] ~]# myname= "$LOGNAME" CCJ

[Email protected] ~]# echo $myname

Rootccj

[[email protected] ~]# myname= ' "$LOGNAME" CCJ ' #先用单引号, then double quotes

[Email protected] ~]# echo $myname

"$LOGNAME" CCJ


When using double quotation marks, the special characters themselves (for example, $) are not canceled, and when single quotes are used, the special characters inside are all going to function.


If you run the Bash command in the current shell, you will enter a new shell, which is the child shell of the original shell. Can be viewed with the Pstree command. (Install pstree command: Yum install-y psmisc) The Pstree command will display all the processes in the Linux system in a tree-shaped structure.

650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/16/bdceb0407a14f58f67c213a5b12e20d3.png "title=" Clipboard (7). png "alt=" Bdceb0407a14f58f67c213a5b12e20d3.png "style=" padding:0px;margin:0px;vertical-align:top; Border:none; "/>

After a variable is set in the parent shell, the variable does not take effect when it enters the child shell. If you want this variable to take effect in a child shell, use the Export command.


The variable ABC is invalid after the current bash defines the variable abc=123 and enters the child bash.

650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/34173c51c9d114aebc7a746a7bdae5a8.png "title=" Clipboard (5). png "alt=" 34173c51c9d114aebc7a746a7bdae5a8.png "style=" padding:0px;margin:0px;vertical-align:top; Border:none; "/>


After declaring the variable with export, the variable can take effect in the child shell (it does not take effect across the terminal).

650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/1f689321f41fb0f4597a979283fad864.png "title=" Clipboard (8). png "alt=" 1f689321f41fb0f4597a979283fad864.png "style=" padding:0px;margin:0px;vertical-align:top; Border:none; "/>


When a variable is set in a child shell, it cannot be applied in the parent shell even if the variable is declared with export, not to the upper layer. When you open multiple terminals, you can use the Echo $SSH _tty to see your terminal:

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/16/a27b350a0314902672f84260b01a3417.png-wh_500x0-wm_3 -wmp_4-s_659650125.png "title=" 6.png "alt=" A27b350a0314902672f84260b01a3417.png-wh_ "/>

The W command is used to display a list of users who have logged in to the system and view the load.


unset variable names can delete variables:

650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/16/f840247cc3989d17ea86a4d488d4de64.png "title=" Clipboard (2). png "alt=" F840247cc3989d17ea86a4d488d4de64.png "style=" padding:0px;margin:0px;vertical-align:top; Border:none; "/>






environment variable configuration file

The environment variable configuration file is divided into: System environment variable profile and user environment variable configuration file.


System environment variable configuration file (no changes allowed)

/etc/profile user Environment variables, interaction, login only execution

This file presets several important variables, such as Path,user,logname, Mail,inputrc,hostname,histsize,umask, and so on.


/ETC/BASHRC the user does not have to log on, the system executes the shell

This file is mainly preset umask and PS1. PS1 is the string of characters in front of the input command.

[Email protected] ~]# echo $PS 1

[\[email protected]\h \w]\$

\u refers to the user, \h refers to the host name, \w refers to the current directory (relative path), \$ refers to the character # (normal user for the $,root user is #), \w refers to the current directory (absolute path)


User environment variable profile (in user home directory)

~/.bash_profile

This file defines the user's personalization path and the file name of the environment variable. Each user can use the file to enter their own shell information, which is executed only once when the user logs on.

~/.bashrc

The file contains bash information for your own shell, which is read when you log in or when you open a new shell. For example, you can write aliases that are never custom or custom variables into this file.

~/.bash_history

This file is used to record historical commands.

~/.bash_logout

When you exit the shell, the file is executed. You can put some cleanup work in this file. For example, the command to clear the history command is placed in this file, and the history command is cleared when the user exits the shell.


650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0035.gif "alt=" J_0035.gif "/>

This article is from the "Operation and maintenance of the Road" blog, please be sure to keep this source http://ccj168.blog.51cto.com/13163491/1982618

Pipe and job control, shell variables, environment variable profiles

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.