管道符作业控制、环境变量shell及环境变量配置文件

10月12日任务

8.6 管道符和作业控制

8.7/8.8 shell变量

8.9 环境变量配置文件

 

8.6 管道符、作业控制

  • cat 1.txt |wc -l ; cat 1.txt |grep 'aaa'

  • ctrl  +z  暂停一个任务   -后台暂停

  • jobs 查看后台的任务

  • bg[id]把任务调到后台   -后台运行

  • fg[id]把任务调到前台

  • 命令后边加&直接丢到后台

#管道符和作业控制

[root@centos6 ~]# cat /etc/passwd |wc -l
20
[root@centos6 ~]# cat /etc/passwd |grep root
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@centos6 tmp]# touch 2.txt
[root@centos6 tmp]# vim 2.txt
[2]+  Stopped                 vim 2.txt
[root@centos6 tmp]# jobs
[1]-  Stopped                 vim /tmp/1.txt
[2]+  Stopped                 vim 2.txt
[root@centos6 tmp]# fg 2
vim 2.txt

 

8.7 、变量

  • PATH ,HOME ,PWD ,LOGNAME

  • env命令   可以获取系统常用变量

  • set命令多了很多变量,包括用户自定义的变量

  • 自定义变量a=1

  • 变量名规则 :字母、数字下划线,首位不能为数字

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

  • 变量的累加

  • 全局变量export b=2

  • unset变量

[root@centos6 ~]# a1=1
[root@centos6 ~]# echo $a1
1
[root@centos6 ~]# a2='a b c'         #单引号可以转义特殊符号
[root@centos6 ~]# echo $a2
a b c
[root@centos6 ~]# a3="a$bc"            #如果用双引号,echo结果不是我们想要的,所以有特俗符号的情况下就要用到单引号
[root@centos6 ~]# echo $a3
a
[root@centos6 ~]# a3='a$bc'
[root@centos6 ~]# echo $a3
a$bc
[root@centos6 ~]# a=1
[root@centos6 ~]# b=2
[root@centos6 ~]# c=a"$b"c              #有特俗用法的时候一定要注意单引号和双引号
[root@centos6 ~]# echo $c
a2c
[root@centos6 ~]# c=a'$b'c
[root@centos6 ~]# echo $c
a$bc

8.8 、变量下

[root@centos6 ~]# w         #w可以查看登陆的终端数量
09:04:37 up 22:23,  2 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/1    2.2.2.104        08:16    0.00s  0.06s  0.00s w
root     pts/2    2.2.2.104        09:04    9.00s  0.03s  0.03s -bash
[root@centos6 ~]# echo $SSH_TTY
/dev/pts/1
[root@centos6 ~]# zgx=linux
[root@centos6 ~]# echo $zgx    #切换终端运行的时候是不会显示的,因为不是全局变量
linux
[root@centos6 ~]# bash
# pstree命令以树状图的方式展现进程之间的派生关系,显示效果比较直观。
[root@centos6 ~]# pstree
init─┬─auditd───{auditd}
     ├─crond
     ├─6*[mingetty]
     ├─ntpd
     ├─rsyslogd───3*[{rsyslogd}]
     ├─sshd─┬─sshd───bash───bash───bash───pstree
     │      └─2*[sshd───bash]
     ├─udevd───2*[udevd]
     └─vmstat
[root@centos6 ~]# echo $zgx
[root@centos6 ~]# exit
exit
[root@centos6 ~]# echo $zgx
linux
[root@centos6 ~]# export zgx=linux           #export 运行全局环境变量,切换终端还是不能显示的,因为两个终端间没有交互
[root@centos6 ~]# echo $zgx
linux
[root@centos6 ~]# bash
[root@centos6 ~]# echo $zgx
linux
[root@centos6 ~]# bash
[root@centos6 ~]# echo $zgx
linux
root@centos6 ~]# pstree
init─┬─auditd───{auditd}
     ├─crond
     ├─6*[mingetty]
     ├─ntpd
     ├─rsyslogd───3*[{rsyslogd}]
     ├─sshd─┬─sshd───bash───bash───bash───pstree
     │      ├─sshd───bash───bash
     │      └─sshd───bash
     ├─udevd───2*[udevd]
     └─vmstat

 

 

8.9、环境变量配置文件

  • /etc/profile  用户环境变量,交互,登陆才执行
  • /etc/bashrc  用户不用登陆,执行shell就能生效 
  • ~/.bashrc
  • ~/.bash_profile
  • ~/.bash_history
  • ~/.bash_logout
  • PS1='\[\033[01;32m\]\u@\h[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '

转载于:https://my.oschina.net/u/3959708/blog/2244720

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值