I'm new to shell scripting I don't understand what the $DISPLAY environmental variable is.

I have Ubuntu 13.10 and I use /bin/bash shell. I have two monitors

We have questions

  1. Command echo $DISPLAY will print :0.0 on my machine (on both monitors). What does this mean?

  2. In which cases will the $DISPLAY variable be blank or NULL?

  3. What are articles or tutorials on this?

Best Answer


The magic word on the x window system is display A display consists of simplified components

  • a keyboard,
  • a mouse
  • and a screen.

The display is managed by a server program known as an x server The server serves displaying capabilities to other programs which connect to it

The remote server knows where to redirect the x network traffic via the definition of the environment variable display which generally points to an x display server on your local computer

The value of the environment variable is

hostname:D.S

where.

hostname is the name of the computer where the X server runs. The omitted hostname means localhost

D is a sequence number typically 0 It can be varied when there are multiple displays connected to one computer

S is the screen number. A display can actually have multiple screens. However there usually is only one screen where default is zero

Example of values

localhost:4
google.com:0
:0.0

hostname:D.S means screen S on display D of host hostname; the X server for this display is listening at TCP port 6000+D.

host/unix:D.S means screen S on display D of host host; the X server for this display is listening at UNIX domain socket /tmp/.X11-unix/XD (so it's only reachable from host).

:D.S is equivalent to host/unix:D.S, where host is the local hostname.

:0.0 means that we are talking about the first screen attached to your first display in your local host

Read more here: support.objectplanet.com and here: superuser.com and here: docstore.mik.ua .

From a x(7) man page.

From the user's perspective, every X server has a display name of the form:

hostname:displaynumber.screennumber

This information is used by the application to determine how it should connect to the server and which screen it should use by default (on displays with multiple monitors):

hostname The hostname specifies the name of the machine to which the display is physically connected. If the hostname is not given, the most efficient way of communicating to a server on the same machine will be used. displaynumber The phrase "display" is usually used to refer to a collection of monitors that share a common keyboard and pointer (mouse, tablet, etc.). Most workstations tend to only have one keyboard, and therefore, only one display. Larger, multi-user systems, however, frequently have several displays so that more than one person can be doing graphics work at once. To avoid confusion, each display on a machine is assigned a display number (beginning at 0) when the X server for that display is started. The display number must always be given in a display name. screennumber Some displays share a single keyboard and pointer among two or more monitors. Since each monitor has its own set of windows, each screen is assigned a screen number (beginning at 0) when the X server for that display is started. If the screen number is not given, screen 0 will be used.