bash忘记了导出变量 [英] bash forgets export variable
本文介绍了bash忘记了导出变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在脚本中,我什至无法进行最简单的变量导出,就无法在bash中工作-我在做什么错了?
I am unable to make even the simplest export of variables, from within scripts, to work in my bash - what am I dooing wrong?
文件 test.sh :
#!/bin/bash
echo $ttt
ttt="fffalse"
export ttt
echo $ttt
bash测试:
hpek@hpek:~/temp$ export ttt="tttrue"
hpek@hpek:~/temp$ ./test.sh
tttrue
fffalse
hpek@hpek:~/temp$ ./test.sh
tttrue
fffalse
hpek@hpek:~/temp$
我现在从答案中知道这是行不通的.-但是如何使进程之间的单个变量被记住?我需要将其存储在文件中吗?
I now know from the answers, that this will not work. -but how can make a single variable remembered between processes? Do I need to store it in a file?
推荐答案
./test.sh
与 bash test.sh
每个运行的shell脚本实际上是一个子进程(子进程).
而且子进程无法将env-var导出到其父级.
Each shell script running is, in effect, a subprocess (child process) of the parent shell.
And subprocess cannot export env-var to it's parent.
您可以尝试此操作(在相同的环境中运行):
You can try this(run in the same environment):
. test.sh
这篇关于bash忘记了导出变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文