我想知道是否有一种方法可以将我的shell变量导出到系统中的所有会话(不仅是当前会话).我不希望在.bashrc文件中设置它,因为shell变量是动态变量,它会不时更改.
I would like to know is there a way to export my shell variable to all sessions in the system (not only the current session). I'm not looking to set it in .bashrc file as the shell variable is a dynamic one it changes time to time.
推荐答案通过在 .bashrc 中的DEBUG上设置陷阱,可以设置会话以继续重新读取磁盘上的文件:
You can set up your sessions to keep rereading a file on disk by setting a trap on DEBUG in your .bashrc:
trap 'source ~/.myvars' DEBUG如果将终端A保持打开状态,请运行 echo VAR = 42>>〜/.myvars 在终端B中,然后切换回终端A并回显$ VAR ,它将被神奇地"设置.
If you leave a terminal A open, run echo VAR=42 >> ~/.myvars in terminal B, then switch back to terminal A and echo $VAR, it'll "magically" be set.
更多推荐
如何将shell变量导出到所有会话?
发布评论