Unix Power ToolsUnix Power ToolsSearch this book

35.8. The DISPLAY Environment Variable

The most important environment variable for X Window System clients is DISPLAY. When a user logs in at an X terminal, the DISPLAY environment variable in each xterm window is set to her X terminal's hostname followed by :0.0.

ruby:joan % echo $DISPLAY
ncd15.ora.com:0.0

When the same user logs in at the console of the workstation named sapphire that's running X, the DISPLAY environment variable is defined as just :0.0:[104]

[104]Before X11 Release 5, the DISPLAY variable might appear as unix:0.0.

sapphire:joan % echo $DISPLAY
:0.0

The DISPLAY environment variable is used by all X clients to determine what X server to display on. Since any X client can connect to any X server that allows it, all X clients need to know what display to connect to upon startup. If DISPLAY is not properly set, the client cannot execute:

sapphire:joan % setenv DISPLAY foo:0
sapphire:joan % xterm
xterm Xt error: Can't open display:

You can override the value of DISPLAY by using the -display command-line option. For example:

sapphire:joan % xterm -display sapphire:0.0 &

The first part of the display name (up to and including the colon) identifies the type of connection to use and the host that the server is running on. The second part (in most cases, the string 0.0) identifies a server number and an optional screen number. In most cases, the server and screen numbers will both be 0. You can omit the screen number name if the default (screen 0) is correct.

Note that we used both :0.0 and sapphire:0.0 to access the local console display of the workstation named sapphire. Although both these names will work, they imply different ways of connecting to the X server.

Note that like all other environment variables set in your shell environment, the DISPLAY environment variable will propagate (Section 35.3) to all processes you start from that shell.

When you run clients from remote machines, some additional problems with the DISPLAY environment variable need to be addressed. See Section 6.10 for more information on running remote clients.

--LM and EP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.