1. 程式人生 > >2018-1-11 5周4次課

2018-1-11 5周4次課

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 [變量名]

[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]#

2018-1-11 5周4次課