8.6 管道符和作业控制

管道符的作用:把前面的命令输出的结果交给后面的命令示例

作业控制 ctrl z 的用法

jobs用法

恢复进程fg +ID号 示例如下

bg,丢到后台去 &输入命令直接丢到后台

8.7/8.8 shell变量

PATH,HOME.PWD,LOGNAME都是变量命令这些命令都是env命令规定的。

自定义变量a=1

变量值有特殊符号时需要用单引号括起来。

变量的累加

定义全局变量:

格式: export [变量名]=[变量值]

[root@shu-test abc]# export aaa=123 [root@shu-test abc]# echo $aaa 123 [root@shu-test abc]#

取消全局变量:

格式: unset [变量名]

[root@shu-test abc]# echo $aaa 123 [root@shu-test abc]# unset aaa [root@shu-test abc]# echo $aaa [root@shu-test abc]#

pstree

pstree命令需要安装psmisc包;

yum install psmisc

查看当前所在bash

[root@shu-test abc]# pstree systemd─┬─NetworkManager───2*[{NetworkManager}] ├─VGAuthService ├─agetty ├─auditd───{auditd} ├─chronyd ├─crond ├─dbus-daemon───{dbus-daemon} ├─firewalld───{firewalld} ├─lvmetad ├─master─┬─pickup │ └─qmgr ├─polkitd───5*[{polkitd}] ├─rsyslogd───2*[{rsyslogd}] ├─sshd───sshd───bash───pstree ├─systemd-journal ├─systemd-logind ├─systemd-udevd ├─tuned───4*[{tuned}] └─vmtoolsd───{vmtoolsd} [root@shu-test abc]#

进入新bash

bash

[root@shu-test abc]# bash [root@shu-test abc]# pstree systemd─┬─NetworkManager───2*[{NetworkManager}] ├─VGAuthService ├─agetty ├─auditd───{auditd} ├─chronyd ├─crond ├─dbus-daemon───{dbus-daemon} ├─firewalld───{firewalld} ├─lvmetad ├─master─┬─pickup │ └─qmgr ├─polkitd───5*[{polkitd}] ├─rsyslogd───2*[{rsyslogd}] ├─sshd───sshd───bash───bash───pstree ├─systemd-journal ├─systemd-logind ├─systemd-udevd ├─tuned───4*[{tuned}] └─vmtoolsd───{vmtoolsd} [root@shu-test abc]#

退出

exit

环境变量 全局的变量(针对所有用户):

    /etc/profile :用户换机变量、交互、登录才执行;
    /etc/bashrc : 用户不用登录、执行shell就生效;

用户home变量文件(只针对当前用户):

    ~/.bashrc:登录或每次打开新的shell时,执行该文件。一般自定义变量写这里;
    ~/.bash_profile:定义用户个人话路径与房价变量文件每次,当用户登录时,改文件仅仅执行一次;
    ~/.bash_history :记录历史命令;
    ~/.bash_logout:退出shell时,执行该文件。可以进行一些清理的工作;

~ 代表家目录 PS1变量

当我们登录系统后,命令的最左边会显示:

[root@shu-test abc]# [root@shu-test abc]#

怎样控制这个显示,那么就要说到PS1变量; PS1变量定义在 /etc/bashrc 文件下面;

[root@shu-test abc]# echo $PS1 [\u@\h \W]$ [root@shu-test abc]#

u@:代表用户名
h:代表hostname
W:代表最后一个路径

注意:可将大W改小w 显示绝对完全路径

实验1:修改显示为绝对路径;

[root@shu-test abc]# echo $PS1 [\u@\h \W]$ [root@shu-test abc]# PS1='[\u@\h \w]$ ' [root@shu-test ~/abc]# cd /etc/sysconfig/ [root@shu-test /etc/sysconfig]#