linux shell全局变量在另一个窗口终端中不可用 [英] linux shell global variable does not available in another window terminal
问题描述
我在Linux操作系统中打开两个终端窗口. 在一个窗口中,键入命令
export a=10
但是在另一个窗口中,我输入
echo $a
它什么也不输出,所以为什么它不起作用.预先感谢.
导出环境变量时,shell的子进程(例如:shell执行的命令)会获取该导出变量的副本. /p>
在两个不同的终端/窗口中运行的Shell就进程而言并不满足这种关系.
如果要设置环境变量,以便每个运行中的shell都可以获取自己的变量实例,请考虑在.bashrc
中定义它(假设您正在使用bash
).但是,您将无法将该变量作为所有正在运行的shell的共享对象"使用(每个shell都有其自己的变量副本).
I open tow terminal windows in my linux OS. In one window, I type the command
export a=10
but in another window, I enter
echo $a
it output nothing, so why it does not work. thanks in advance.
When you export an environmental variable, the child processes of the shell (e.g.: the commands executed by the shell) do obtain a copy of that exported variable.
Shells running in two different terminals/windows do not fulfill this relationship in terms of processes.
If you want to set an environmental variable, so that every running shell will obtain a its own instance of the variable, consider defining it in .bashrc
(assuming you are using bash
). However, you won't be able to use this variable as a one "being shared" by all the running shells (each shell has its own copy of the variable).
这篇关于linux shell全局变量在另一个窗口终端中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!