Pipe and job control, shell variables, environment variable configuration files

Source: Internet
Author: User

Pipe character and job control
    • | Give the result of the previous command to the following command processing.
      [[email protected] ~]# cat 1.txt |wc -l  统计行数5[[email protected] ~]# cat 1.txt |grep ‘aaa‘aaaa   剪切出aaa的行
    • CTRL Z pauses a task, which can only be operated at the current terminal, and the other terminal will be able to check the process
    • Jobs view the tasks in the background
    • BG [ID] The task to the background, no ID default last
    • FG [ID] The task to the foreground, no ID default last
    • command to add & drop directly into the background,
      [[email protected] ~]# sleep 200    暂停200秒^Z[1]+  已停止               sleep 200[[email protected] ~]# jobs[1]+  已停止               sleep 200[[email protected] ~]# fg 1sleep 200[[email protected] ~]# bg 1[1]+ sleep 200 &[[email protected] ~]# jobs[1]+  运行中               sleep 200 &[[email protected] ~]# [[email protected] ~]# sleep 100 &[1] 2213[[email protected] ~]# jobs[1]+  运行中               sleep 100 &
Shell variables
  • Path,home,pwd,logname are all variables.
  • EVN command displays the environment variables of the system
  • The set command not only can view the environment variables of the system, but also can view the user-defined variables, many of which are set |less to see more convenient
  • Custom variable: a=111
    [[email protected] ~]# a=111[[email protected] ~]# echo $a111[[email protected] ~]# set |grep 111_=111a=111
  • Rules for variable names: letters, numbers, underscores, numbers cannot be the first
    [[email protected] ~]# a1=1[[email protected] ~]# a_1=2[[email protected] ~]# 1a=3-bash: 1a=3: 未找到命令
  • The value of a variable must be enclosed in single quotation marks when it has a special symbol, not double quotes, and some special symbols cannot be used.
    [[email protected] ~]# a=‘a b c‘[[email protected] ~]# a="a$bc"[[email protected] ~]# echo $aa[[email protected] ~]# a=‘a$bc‘[[email protected] ~]# echo $aa$bc
  • The sum of the variables, if one variable refers to another variable, enclose the double quotation mark, cannot add the single quotation mark.
    [[email protected] ~]# a=1[[email protected] ~]# b=2[[email protected] ~]# echo $a$b12[[email protected] ~]# c=a"$b"c[[email protected] ~]# echo $ca2c
  • Global variables Export a=12 set a global variable, just down the sub-shell copy down, in its upper level shell and other terminals do not take effect, script 1 inside the nested script 2,2 can use the variables inside 1
    [[email protected] ~]# w09:41:58 up 57 min,  1 user,  load average: 0.00, 0.01, 0.05USER     TTY      FROM             [email protected]   IDLE   JCPU   PCPU WHATroot     pts/0    192.168.16.1     08:48    6.00s  0.62s  0.16s w[[email protected] ~]# echo $SSH_TTY 查看自己的登录TTY/dev/pts/0pstree命令以树状图的方式展现进程之间的派生关系,显示效果比较直观
  • Unset variable name---cancel variable
environment variable configuration file
    • /etc/profile user Environment variables, interaction, login to execute, this is a system-level global variable
    • /ETC/BASHRC the user does not need to log in, executes the shell to be effective, usually does not edit
    • ~/.bash_profile there is a need to edit the user's own environment variables
    • source. Bash_profile make its changes effective
    • ~/.bashrc
    • The. Bash_profile startup invokes the. BASHRC,.BASHRC calls the system's BASHRC
    • To configure environment variables, the most insurance is written in the. bashrc file. Because the file will always be called, whether it be landed or not!
    • ~/.bash_history User's command history file
    • ~/.bash_logout allows the user to delete the command history each time they exit the command can be added to this file
    • Ps1= ' [[\033[01;32m]\[email protected]\h[\033[00m]:[\033[01;36m]\w[\033[00m]]\$ ' with color display settings command input to the left to display information, PS2 settings into other terminal display such as MySQL command input effect display
      [[email protected] ~]# echo $PS1[\[email protected]\h \W]\$u显示登录的用户,h显示登录的机器名,W显示当前目录名,$显示用户级别普通用户显示$root用户显示#[[email protected]]$PS1=‘[\[email protected]\h \w]\$‘[[email protected] /etc/sysctl.d]#
Extended
    • Bash_profile and BASHRC differences
    • Simple Audit system
    • About the meaning of Prompt_command environment variables

Pipe and job control, shell variables, environment variable configuration files

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.