管道符和做業控制、shell變量、環境變量配置文件

管道符|

將前一個指令的輸出做爲後一個指令的輸入shell

[root@centos01 ~]# cat err.txt | wc -l
1

做業控制

  • ctrl+z 臨時暫停當前的任務
  • jobs查看後臺的任務
  • bg[id]把任務調到後臺
  • fg[id]把任務調到前臺
  • 命令後面加&直接丟到後臺
[root@centos01 ~]# vim err.txt

[1]+  Stopped                 vim err.txt
[root@centos01 ~]# fg
vim err.txt

[1]+  Stopped                 vim err.txt
[root@centos01 ~]# vim ttt.log

[2]+  Stopped                 vim ttt.log
[root@centos01 ~]# jobs
[1]-  Stopped                 vim err.txt
[2]+  Stopped                 vim ttt.log
[root@centos01 ~]# fg 2
vim ttt.log
[root@centos01 ~]# jobs
[1]+  Stopped                 vim err.txt

shell變量

  • 常見的系統變量PATH,HOME,PWD,LOGNAME
  • env命令,查看系統的一些經常使用環境變量
  • set命令多了不少變量,而且包括用戶自定義的變量
  • 自定義變量a=1
  • 變量名規則:字母、數字下劃線,首位不能爲數字
  • 變量值有特殊符號時須要用單引號括起來
  • 變量累加
  • 全局變量export b=2
  • unset變量,取消某個變量
[root@centos01 ~]# a=111
[root@centos01 ~]# echo $a
111
[root@centos01 ~]# set | grep 111
_=111
a=111
[root@centos01 ~]# a="a$bc"
[root@centos01 ~]# echo $a
a
[root@centos01 ~]#
[root@centos01 ~]# a='a$bc'
[root@centos01 ~]# echo $a
a$bc
[root@centos01 ~]# a=1
[root@centos01 ~]# b=2
[root@centos01 ~]# echo $a$b
12
[root@centos01 ~]# a='a$bc'
[root@centos01 ~]# echo $a$b
a$bc2
[root@centos01 ~]# c="a$bc"
[root@centos01 ~]# echo $c
a
[root@centos01 ~]# echo "a$b"c
a2c

[root@centos01 ~]# export test001=111
[root@centos01 ~]# bash
[root@centos01 ~]# echo $test001
111

環境變量配置文件vim

  • /etc/profile 用戶環境變量,交互,登陸才執行
  • /etc/bashrc 用戶不用登陸,執行shell就生效
  • ~/.bashrc 包含專屬於本身的shell的bash信息,當登陸或每次打開新的shell時,該文件會被讀取。
  • ~/.bash_profile 定義了用戶的我的化路徑與環境變量的配置文件。每一個用戶均可使用 該文件輸入專屬於本身的shell信息,當用戶登陸時,該文件僅僅執行一次。
  • ~/.bash_history 記錄命令歷史命令文件
  • ~/.bash_logout 當退出shell是,會執行該文件。
  • PS1 命令輸入前命令行前面的字符控制變量
相關文章
相關標籤/搜索