8.6 Pipelines and job control
1、cat 1.txt |wc -l ; cat 1.txt |grep 'aaa'
2. ctrl+z pauses a task ( ctrl +c terminates)
3. jobs view background tasks
4. bg[id] transfers the task to the background ( short for background) to make it run in the background
5. fg[id] transfers the task to the foreground ( short for foreground) command to resume
6. Add & after the command and throw it directly to the background to continue running
pipe character
1.1 The pipe character "|" is to pass the result of the previous command to the following command
job control
1.2 How to pause the operation and exit when we are editing a file, we can enter ctrl + z to pause the task
1.3 jobs View tasks that are suspended or running in the background , the first column has an ID number
1.4 bg[id] transfers the task to the background to run;
1.5 fg[id] transfers the task to the foreground to run
1.6 Add & after the command and throw it directly to the background, sleep 100 refers to suspending for 100 seconds, and the background continues to run
8.7-8.8 Shell variables
The environment variable PATH is a variable preset by the shell , and the preset variables are usually capitalized. A variable is to use a simpler string to replace certain settings and data with special meaning. System default environment variables: PATH , HOME , LOGNAME
1.1 PATH , HOME , PWD , LOGNAME // System variables (can be viewed with echo , such as echo $PATH )
1.2 env command // View system environment variable information
1.3 The set command has many more variables, and includes user -defined variables //shell scripts
1.4 Custom variables
The variable name rules can be: alphanumeric underscore , the first position cannot be a number
Variable values that have special symbols need to be enclosed in single quotes
1.4.1 Custom variable a=1 , example
1.4.2 Variable name rules: letters and numbers are underlined, and the first position cannot be a number . Example
1.4.3 When the variable value has special symbols, it needs to be enclosed in single quotation marks , for example:
1.5 Accumulation of variables, example:
If the variable content itself has single quotes or other symbols such as $ , this requires double quotes
1.6 Global variable export ( valid for the next sub- bash , but not for the upper level)
When we customize a variable on a terminal, it is only valid for the shell under the current terminal. If a subshell is opened under this terminal , the variable will not be synchronized in the past. This is called a non-global variable . If you want all subshells to synchronize this custom variable, use the global variable command : export (only valid from top to bottom, not vice versa )
bash是shell的一个子bash,可以通过pstree查看在哪个层级
1.7 如果要取消自定义的变量,使用命令:unset 变量名
8.9 环境变量配置文件
1.系统层次etc下面,用户登录加载使用,一般不要动(不要修改):
/etc/profile 用户环境变量,交互,登录才执行
2、用户层次,在用户家目录下,用户执行shell脚本的时候生效,一般不要动:
/etc/bashrc //用户不用登录,执行shell就生效
~/.bashrc //执行shell脚本时的配置文件
~/.bash_profile //用户登录时自动加载配置文件
~/.bash_history //记录命令历史的文件
~/.bash_logout //用来定义用户退出时需要做的操作
备注:每个用户下都会有两个隐藏文件,这两种文件的区别在于用户登录时自动加载profile,而profile也会自动调用bashrc,bashrc是执行shell脚本的时候,用户不用登录,就会自动执行shell脚本,只要执行shell脚本,就会调用bashrc里面的配置文件。
2 3 4 |
[root@aminglinux-01 ~]# vim .bash_profile [root@aminglinux-01 ~]#source .bash_profile //source执行加载这个文件命令 [root@aminglinux-01 ~]#. .bash_profile //.与source命令一样作用 [root@aminglinux-01 ~]# vim .bashrc |
2.1 /etc/bashrc :这个文件主要预设umask以及PS1。这个PS1就是我们在敲命令时,前面那串字符了:
( \u is the user, \h hostname, \W is the current directory, $ is the '#' , if it is a normal user, it will be displayed as '$' )
2.1.2 Environment variables that change the way the user line is displayed , with color settings:
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '