bash 为什么 $DISPLAY 有时是 :0 有时是 :1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14394974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:17:48  来源:igfitidea点击:

Why is $DISPLAY sometimes :0 and sometimes :1

bashenvironment-variables

提问by Trong Truong

I'm using xmacro to record keyboard shortcuts, which requires a $DISPLAYto replay on. But, sometimes my $DISPLAYis :0and sometimes :1, so every time that happens I have to change the value manually. Why does it keep changing, and is there a way to set the $DISPLAYvalue to either :0or :1permanently? (I can export DISPLAY=:0in one terminal, but that doesn't change the value of $DISPLAYin new terminals.)

我正在使用 xmacro 记录键盘快捷键,这需要$DISPLAY重播。但是,有时我$DISPLAY:0有时是:1,所以每次发生这种情况时我都必须手动更改该值。为什么它会不断变化,有没有办法将$DISPLAY值永久设置为:0:1?(我可以DISPLAY=:0在一个终端中导出,但这不会改变$DISPLAY新终端中的值。)

回答by Aaron Digulla

The number identifies the display ("a collection of monitors that share a keyboard and mouse")

数字标识显示器(“一组共享键盘和鼠标的显示器”)

:0is usually the local display (i.e. the main display of the computer when you sit in front of it).

:0通常是本地显示器(即你坐在电脑前的主显示器)。

:1is often used by services like SSH when you enable display forwarding and log into a remote computer.

:1当您启用显示转发并登录到远程计算机时,SSH 等服务通常会使用 SSH。

It can also be modified by startup scripts which try to "fix" it. To find out whether this is happening, run

它也可以通过尝试“修复”它的启动脚本进行修改。要查明是否发生这种情况,请运行

grep DISPLAY ~/.??*

.??*is a trick to get all dot files without ..and .(parent and current folder).

.??*是获取所有没有...(父文件夹和当前文件夹)的点文件的技巧。

If that doesn't print anything, check /etc/profile, /etc/bash*and /etc/bash*/*in a similar manner.

如果没有显示任何信息,检查/etc/profile/etc/bash*/etc/bash*/*以类似的方式。

I couldn't find a useful manual for xmacro but most X11 application support the option -dor -displayto override $DISPLAY.

我找不到 xmacro 的有用手册,但大多数 X11 应用程序都支持该选项-d-display覆盖$DISPLAY.

If this doesn't work, create xmacro.shwith this content:

如果这不起作用,请xmacro.sh使用以下内容创建:

 #!/bin/bash

 export DISPLAY=:0
 exec xmacro "$@"

Now invoke the tool with xmacro.shand it should always work.

现在调用该工具,xmacro.sh它应该始终有效。