leeboy的linux学习十三环境变量实例
环境变量和本地变量的区别在于是不是具有继承性,下面介绍一个环境变量的例子:
exportFather父进程:
#!/bin/sh#father scriptecho "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 fileecho "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 fatherI like the file : A GOOD MANthis is ChildI like my father's file : A GOOD MANmy file is : Child Fileback to fatherand the file is : A GOOD MAN//环境变量在子进程中修改但父进程中没有变化
如果我想在子进程中修改的环境变量也能影响到主进程的改环境变量,该如何做呢?望大牛指导!