tool logo shel 怎样 ffffff port yum 退出 onf
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 [变量名]
pstree 命令需要安装 psmisc 包;
[root@shu-test abc]# echo $aaa
123
[root@shu-test abc]# unset aaa
[root@shu-test abc]# echo $aaa
[root@shu-test abc]#
pstree
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
systemd─┬─NetworkManager───2[{NetworkManager}]
bash
[root@shu-test abc]# bash
[root@shu-test abc]# pstree
├─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 变量
当我们登录系统后,命令的最左边会显示:
怎样控制这个显示,那么就要说到 PS1 变量;
[root@shu-test abc]#
[root@shu-test abc]#
PS1 变量定义在 /etc/bashrc 文件下面;
u@:代表用户名
[root@shu-test abc]# echo $PS1
[\u@\h \W]\$
[root@shu-test abc]#
h:代表hostname
W:代表最后一个路径
注意:可将大W改小w 显示绝对完全路径
实验 1:修改显示为绝对路径;
2018-1-11 5 周 4 次课
[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]#
来源: http://www.bubuko.com/infodetail-2458165.html