8.6-8.9 pipe and job control, shell variables, environment variables

Source: Internet
Author: User

8.6 Pipe break and job control pipe symbol "|"

The effect of a pipe character is to drop the result preceding the symbol to the command following the symbol. Not all commands are available after the pipe character, and generally commands for document operations are common, eg:cat, less, head, tail, grep, cut, sort, WC, uniq, tee, tr, split, SED, awk, and more.

Job Control
    • CTRL + Z pause a task that is being performed

    • Jobs view tasks running in the background

    • Bg[id] =background to run the task in the background

    • Fg[id] =foreground The mission to the foreground.

    • The "&" command followed by & is equivalent to directly moving the task to the background to run
8.7-8.8 Shell variables
    • ENV command: View system built-in environment variables
[[email protected] tmp]# envXDG_SESSION_ID=2HOSTNAME=gaohanwei        主机名TERM=xtermSHELL=/bin/bashHISTSIZE=1000SSH_CLIENT=192.168.8.1 51650 22OLDPWD=/tmp/test.isoSSH_TTY=/dev/pts/0USER=root……

You can also use the SET command to view shell variables, which can display not only the system's built-in environment variables, but also user-defined environment variables.

Custom variables
[[email protected] tmp]# set |grep adia[[email protected] tmp]# set |grep adaiHOSTNAME=gaohanweig=gao

Variable name rules: Letters, numbers underline, the first can not be a number, the value of the variable has a special symbol should be enclosed in single quotation marks (single quotation marks have a de-meaning function).

    • Variable accumulation
[[email protected] tmp]# a=123[[email protected] tmp]# b=456[[email protected] tmp]# echo $a$b123456[[email protected] tmp]# d="$c0"  此写法不合法,所以变量d不会被赋值[[email protected] tmp]# echo $d(空白)[[email protected] tmp]# c="$a$b"789[[email protected] tmp]# echo $c123456789

Note: When multiple variables are superimposed, double quotation marks are required on the target variable (right side of the equals sign) and are written when new values are appended to the new variable: c= "$a $b" 789.

Global variables
    • Export
      When a variable is set under a parent shell, the variable does not take effect, and if you want the variable to take effect under the child shell, you need to use export to declare it (not valid across terminals). Syntax: Export [variable name]
      When export does not specify a variable, it declares all variables of the system.
[[email protected] ~]# a=gaolinux[[email protected] ~]# echo $agaolinux[[email protected] ~]# export a=gaolinux[[email protected] ~]# echo $agaolinux[[email protected] ~]# bash[[email protected] ~]# echo $agaolinux

Description: When a variable is set in a child shell, it cannot be applied to the parent shell even after it is declared.

    • When opening multiple terminals, use the following command to view your current terminal:
[[email protected] tmp]# w查看当前正在运行的所有端口 16:48:33 up  1:28,  3 users,  load average: 0.00, 0.01, 0.05USER     TTY      FROM             [email protected]   IDLE   JCPU   PCPU WHATroot     tty1                      15:21    1:27m  0.05s  0.05s -bashroot     pts/0    192.168.8.1      15:21    1.00s  0.20s  0.01s wroot     pts/1    192.168.8.1      16:46    1:53   0.01s  0.01s -bash[[email protected] tmp]# echo $SSH_TTY查看当前窗口所在终端/dev/pts/0
    • Bash Command &pstree command
[[email protected] ~]# bash[[email protected] ~]# pstreesystemd─┬─NetworkManager───2*[{NetworkManager}]        ├─auditd───{auditd}        ├─chronyd        ├─crond        ├─dbus-daemon        ├─firewalld───{firewalld}        ├─login───bash        ├─lvmetad        ├─master─┬─pickup        │        └─qmgr        ├─polkitd───5*[{polkitd}]        ├─rsyslogd───2*[{rsyslogd}]        ├─sshd───sshd─┬─bash───bash───pstree        │             └─bash        ├─systemd-journal        ├─systemd-logind        ├─systemd-udevd        ├─tuned───4*[{tuned}]        └─vmtoolsd───{vmtoolsd}

Running the Bash command in the current Shell China will enter a new shell, the shell of the original shell, which can be used to print all the processes in the system in a tree-like structure using the Pstree command. The Pstree row shows the currently located shell (exit can exit the child shell).

Delete variable unset
    • Syntax: unset [variable name]
[[email protected] ~]# echo $abc123[[email protected] ~]# unset abc[[email protected] ~]# echo $abc
8.9 environment variable configuration file

The environment variable profile can be divided into two dimensions: the system environment variable profile and the user environment variable configuration file.

System configuration file (no changes allowed)
    • /etc/profile user Environment variables, interaction, login only execution
    • /ETC/BASHRC user does not need to log in, the execution shell is effective user profile
~/.bashrc

This file contains bash information dedicated to your shell, which is read when you log on and every time you open a new shell. For example, you can write user-defined alias or custom variables to this file.

~/.bash_profile

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

~/.bash_history

Record the command history used.

~/.bash_logout

When you exit the shell, the file is executed. You can put some cleanup work into this file (such as clearing the cache, clearing the history, and so on).

Variable "PS1"

This PS1 is the string of characters we have in front of the command, such as my Linux system PS1 [[email protected] ~]#, we might as well look at the value of PS1:

[[email protected] ~]# echo $PS1[\[email protected]\h \W]\$

Description: \u is the user, \h hostname, \w is the current directory, \$ is that ' # ', if the average user is displayed as ' $ '.

8.6-8.9 pipe and job control, shell variables, environment variables

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.