1、查看系统环境变量:env、export
2、查看自定义变量: set、declare
测试系统环境变量:
[root@rhel7pc1 test]# ls
[root@rhel7pc1 test]# env > a.txt && export > b.txt ## 将env和export命令的输出结果保存为文件
[root@rhel7pc1 test]# wc -l * ## 统计行数
25 a.txt
24 b.txt
49 total
[root@rhel7pc1 test]# head -n 2 a.txt ## 查看前两行
XDG_SESSION_ID=17
HOSTNAME=rhel7pc1
[root@rhel7pc1 test]# head -n 2 b.txt
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE="1000"
[root@rhel7pc1 test]# sort a.txt > a && mv a a.txt ## 排序
[root@rhel7pc1 test]# awk '{print $3}' b.txt | sed 's/"//g' | sort > a && mv a b.txt ## 转化为a.txt格式并排序
[root@rhel7pc1 test]# ls
a.txt b.txt
[root@rhel7pc1 test]# diff a.txt b.txt ## 比较两个文件的差异
6c6
< LESSOPEN=||/usr/bin/lesspipe.sh %s
---
> LESSOPEN=||/usr/bin/lesspipe.sh
18,19c18,19
< SSH_CLIENT=192.168.83.1 60760 22
< SSH_CONNECTION=192.168.83.1 60760 192.168.83.129 22
---
> SSH_CLIENT=192.168.83.1
> SSH_CONNECTION=192.168.83.1
23d22
< _=/usr/bin/env
说明env和export命令生成的文件基本相同。
测试自定义变量:
[root@rhel7pc1 test]# ls [root@rhel7pc1 test]# set > a.txt [root@rhel7pc1 test]# declare > b.txt [root@rhel7pc1 test]# wc -l * 4946 a.txt 4946 b.txt 9892 total [root@rhel7pc1 test]# diff a.txt b.txt 67c67 < _=--color=auto --- > _=set
说明set命令和declare生成的命令基本一样。
原创文章,作者:jamestackk,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/245123.html