linux 中使用export设置的变量为环境变量、没有使用export设置的变量为自定义变量

 

1、Shell 的变量,可以分为“环境变量”和“自定义变量”两种类型,两者的区别在于作用范围不同。环境变量可以在其进程的子进程中继续有效,而自定义变量的势力范围则无法延伸到其进程的子进程中

 

[root@localhost test]# ls
[root@localhost test]# A=100    ## 自定义变量
[root@localhost test]# echo $A
100
[root@localhost test]# B=200    ## 自定义变量
[root@localhost test]# echo $B
200
[root@localhost test]# export A  ## 将A定义为环境变量
[root@localhost test]# bash      ## 进入到一个bash子进程
[root@localhost test]# echo $A   ## 环境变量在子进程中仍然可见
100
[root@localhost test]# echo $B   ## 自定义变量在子进程中不可见

 

参考:http://c.biancheng.net/linux/export.html

 

posted @ 2022-03-28 21:59  小鲨鱼2018  阅读(238)  评论(0编辑  收藏  举报