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/1d984a59004a96e2f826e971888f9636.png "title=" Clipboard.png "alt=" 1d984a59004a96e2f826e971888f9636.png "/>


Job Control

When running a process, we can use CTRL +z to pause it, then use the FG (foreground) command to recover it, or make it run in the background with the command BG (background) command. You can also use CTRL + C to terminate it. Jobs can view tasks running in the background.

650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/a7ec17a5edc3f5a243b12239fdbf24dc.png "title=" Clipboard (1). png "alt=" A7ec17a5edc3f5a243b12239fdbf24dc.png "/>



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 "/>

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 multilingual environment

Home: Indicates the current user's home directory

LOGNAME: Indicates the login name of the current user


The env command displays variables that are only environment variables.


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://s3.51cto.com/oss/201711/16/062ec24938d4138b8bb4c8eaae28d380.png "title=" Clipboard (4). png "alt=" 062ec24938d4138b8bb4c8eaae28d380.png "/>

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=huang da

-bash:da: Command not found

[Email protected] ~]# myname= ' Huang Da '

[Email protected] ~]# echo $myname

Huang Da


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

[Email protected] ~]# myname= ' Huang ' da '

> ^c

[Email protected] ~]# myname= "Huang ' da"

[Email protected] ~]# echo $myname

Huang ' da


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" HUANG

[Email protected] ~]# echo $myname

Roothuang

[[email protected] ~]# myname= ' "$LOGNAME" HUANG '

#先用单引号, then double quotation marks

[Email protected] ~]# echo $myname

"$LOGNAME" HUANG


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 "/>


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 "/>

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 "/>


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!


When you open multiple terminals, you can use the Echo $SSH _tty to see your terminal:

650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/16/f74760c7142d9b47a8f565998c8dcda0.png "title=" Clipboard (3). png "alt=" F74760c7142d9b47a8f565998c8dcda0.png "/>

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 "/>



environment variable configuration file

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


Department environment variable configuration file (no changes are prohibited)

/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.


This article is from the "Network Management Learning Road" blog, please be sure to keep this source http://754599082.blog.51cto.com/11510506/1982478

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.