如果示例代码中有错误,请见谅。
有两个文件 testA.sh 和 testB.sh。
测试文件
#!/bin/bash
export a="hello"
source testb.sh
测试文件
#!/bin/bash
echo "test b"
echo $a
deepak[18:33] $ ./testA.sh
test b
你好
deepak[18:33] $ echo $a
迪帕克[18:33] $
如果我们在 testB.sh 中运行任何设置,那么我们如何在主控制台中使用该设置或 env 变量(例如 echo $a)
testA.sh 在子shell 中运行,当它结束时,它的环境也随之消失。
如果你source testA.sh
会保持价值。
$: ./testA.sh
test b
hello
$: echo $a
$: . ./testA.sh
test b
hello
$: echo $a
hello
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句