Pipe and Job control & Shell variables & environment variable profiles

Source: Internet
Author: User

Pipe symbol |

Used to input the output of the previous instruction as the last instruction

[email protected]]# Cat 1.txt | Wc-l
2
[email protected]]# cat 1.txt
1.txt
2.txt

[[email protected]]# find./-type F | Wc-l
37

Job Control

When the process is running, press CTRL + Z to pause it, then use the FG command to recover it, or use the BG command to make it run in the background. CTRL + C can make it stop.

[Email protected]]# vim 1.txt

[1]+ has stopped Vim 1.txt

[[email protected]]# FG transferred to the front desk.

[Email protected]]# vim Aa.txt

[2]+ has stopped Vim Aa.txt
[[email protected]]# jobs
[1]-has stopped Vim 1.txt
[2]+ has stopped Vim Aa.txt

[[email protected]]# FG 2 foreground call 2,aa.txt

[[email protected]]# BG 2 background Call 2
[2]+ Vim Aa.txt &
[[email protected]]# jobs
[1]-has stopped Vim 1.txt
[2]+ has stopped Vim Aa.txt

[[email protected]]# FG 2:q exit
Vim Aa.txt
[[email protected]]# jobs
[1]+ has stopped Vim 1.txt

[[email protected]]# sleep 1000 sleeps 1000 seconds
^z
[1]+ has stopped sleep + Ctrl + Z pause
[[email protected]]# jobs
[1]+ has stopped sleep 1000
[[email protected]]# Sleep 200 sleeps 200 seconds
^z Ctrl + Z Pause
[2]+ has stopped sleep 200
[[email protected]]# jobs
[1]-has stopped sleep 1000
[2]+ has stopped sleep 200
[[email protected]]# FG foreground call last task Sleep 200
Sleep 200
^z then pause
[2]+ has stopped sleep 200
[[email protected]]# BG 1 background Run sleep 1000
[1]-Sleep &
[[email protected]]# jobs
[1]-Run in Sleep &
[2]+ has stopped sleep 200

[[email protected]]# FG 1
Sleep 1000
^c
[[email protected]]# FG 2
Sleep 200
[Email protected]]# ^c
[[email protected]]# jobs

[[email protected]]# Sleep & Sleep 100 command dropped directly into the background to run
[1] 2632
[[email protected]]# jobs
[1]+ Run in Sleep &

ENV command

You can list all system variables for system presets

[[Email protected]]# env only lists the parts
Xdg_session_id=1
Hostname=lizhipeng01
Selinux_role_requested=
Term=xterm
Shell=/bin/bash
histsize=5000
ssh_client=192.168.5.1 3399 22
Selinux_use_current_range=
ssh_tty=/dev/pts/0
User=root
LS_COLORS=RS=0:DI=01;34:LN=01;36:

HOSTNAME: Indicates host name

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: Language-related environment variables

Home: Indicates the current user's home directory

LOGNAME: Indicates the login name of the current user

Set command
Similar to the ENV command, you can export environment variables. The SET command can display not only the system preset variables, but also user-defined variables.

[Email protected]]# Myname=lizhipeng
[Email protected]]# echo $myname
Lizhipeng
[[Email protected]]# set |grep myname
Myname=lizhipeng

But this custom variable can only take effect in the current shell.

[Email protected]]# Name=li
[Email protected]]# echo $name
Li
[Email protected]]# bash
[Email protected]]# echo $name

[[Email protected]]# exit
Exit
[Email protected]]# echo $name
Li

With the Bash command, you can open a shell again, and the previously set name variable no longer exists, leaving the current shell back to the original shell,name variable. There are two ways to make the environment variable that you set to work.

1. Allow all users in the system to log in and use the variable. Practice: Add the export Name=li to the last line of the/etc/profile file, and then run Source/etc/profile to take effect. Run the Bash command again or switch to another account to see the effect

[Email protected]]# Vi/etc/profile
[Email protected]]# Source/etc/profile
[Email protected]]# echo $name
Li
[Email protected]]# bash
[Email protected]]# echo $name
Li

[Email protected]]# Su-lizhipeng
Last login: 212 months 07:11:46 CST 2017 from 192.168.5.1pts/0
[Email protected] ~]$ echo $name
Li

2. Allow only the current user to use the variable. How to do this: in the user home directory, the last line of the. bashrc file is added to export name=li2, and then source. BASHRC can take effect. The purpose of the source command is to refresh the currently configured configuration, which can take effect without logging off or logging on.

[Email protected]]# Vi. BASHRC
[[email protected]]# echo $name not valid because there is no source
Li
[[email protected]]# source. BASHRC
[[email protected]]# echo $name in effect
Li2
[Email protected]]# Su-lizhipeng
Last login: 41 months 04:49:12 CST 2018pts/0
[Email protected] ~]$ echo $name
Li

Variable definition rules

1. The format of the variable is a=b, where a is the variable name, B is the contents of the variable, there is no space on either side of the equal sign;

2. Variable names can only consist of letters, numbers, and underscores, and cannot begin with a number.

3. When the contents of a variable have special characters (such as spaces), you need to add single quotation marks

[Email protected]]# name= ' Li Ju '
[Email protected]]# echo $name
Li Ju
[[email protected]]# name= "Li's" when the variable content itself with a single quote, which is required double quotation marks
[Email protected]]# echo $name
Li ' s

[[email protected]]# name= ' pwd ' If you need to use other commands in the variable contents, you can use the inverse quotation mark to run the result
[Email protected]]# echo $name
/root

[[email protected]]# name= "$name" AAA variable cumulative, plus double quotes
[Email protected]]# echo $name
/rootaaa

[Email protected]]# name= ' $name ' AAA plus a single quote, inside the special characters all lose their own role
[Email protected]]# echo $name
$nameAAA

Configuration files for system environment variables and personal environment variables

/etc/profile: This file presets several important variables, such as path, USER, LOGNAME, MAIL, INPUTRC, HOSTNAME, histsize, umask, etc.

/ETC/BASHRC: Preset umask and PS1. PS1 is the string of characters that precedes us when we enter a 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, \$ refers to the character # (if it is a normal user, then display $)

. 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: This file contains bash information for your own shell, which is read when you log in or open a new shell every time.

. bash_history: This file is used to record command history.

. bash_logout: When you exit the shell, the file is executed.

[Email protected]]# echo $PS 2
>
[[email protected]]# for i in ' SEQ 1 10 '
> Do
> Echo $i
> Done

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.