leeboy的linux学习十三环境变量实例

环境变量和本地变量的区别在于是不是具有继承性,下面介绍一个环境变量的例子:

exportFather父进程:

#!/bin/sh
#father script
echo "this is the father"
FILE="A GOOD MAN"
echo "I like the file : $FILE"
export FILE     #声明为环境变量,如果此处不声明,exportChild无法使用该变量
./exportChild   #执行子进程
echo "back to father"
echo "and the file is : $FILE"


exportChild  子进程:

#!/bin/sh
#child file
echo "this is Child"
echo "I like my father's file : $FILE"
FILE="Child File"           #子进程中修改该环境变量对主进程中没有影响
echo "my file is : $FILE"


执行结果如下:

[root@localhost textFile]# ./exportFather 
this is the father
I like the file : A GOOD MAN
this is Child
I like my father's file : A GOOD MAN
my file is : Child File
back to father
and the file is : A GOOD MAN		//环境变量在子进程中修改但父进程中没有变化


 如果我想在子进程中修改的环境变量也能影响到主进程的改环境变量,该如何做呢?望大牛指导!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值