Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am new to shell script NOT able to understand what is $DISPLAY environment variable.

I am running Ubuntu 13.10 and using /bin/bash shell. I have connected two monitors.

Questions:

  1. echo $DISPLAY will print :0.0 on my machine(on Both monitors). What this means?

  2. In which case $DISPLAY will be blank or NULL?

  3. Are there any articles or tutorials on this?

share|improve this question
    
Today echo $DISPLAY is printing :0 NOT :0.0 –  Chandrayya G K Mar 11 at 7:22
    
check this will help in case of blank or errors : askubuntu.com/questions/432610/… –  Ask Mar 11 at 12:08

3 Answers 3

up vote 14 down vote accepted

The magic word in the X window system is DISPLAY. A display consists (simplified) of:

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

A display is managed by a server program, known as an X server. The server serves displaying capabilities to other programs that connect to it.

The remote server knows where it have to redirect the X network traffic via the definition of the DISPLAY environment variable which generally points to an X Display server located on your local computer.

The value of the display environment variable is:

hostname:D.S

where:

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

D is a sequence number (usually 0). It can be varied if there are multiple displays connected to one computer.

S is the screen number. A display can actually have multiple screens. Usually there's only one screen though where 0 is the default.

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 and here and here.

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 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.

share|improve this answer
    
When this $DISPLAY will be null or BLANK. –  Chandrayya G K Mar 11 at 7:16
    
In normal This must not happen unless there is a problem in your display.. Mostly a restart of your display manager will solve the problem. But this is not a default action. –  Ask Mar 11 at 8:42
    
askubuntu.com/questions/432610/… –  Ask Mar 11 at 12:10

echo $DISPLAY will print :0.0 on my machine(on Both monitors). What this means?

:0.0 means display number 0 and screen number 0

In which case $DISPLAY will be blank or NULL?

In case of error in your $DISPLAY and this doesn't happen normally

Are there any articles or tutorials on this?

Some tutorials and resource can be found here:

share|improve this answer

From https://help.ubuntu.com/community/EnvironmentVariables:

Variable- DISPLAY

Values Example:

:0.0
localhost:10.0
terminal01:0.0

What it's for?

This variable is used to indicate to graphical applications where to display the actual graphical user interface, the value consists of 3 parts: A host-name followed by a colon (:), a display number followed by a dot (.) and a screen number.

The host-name part can be used to have the graphical output sent to a remote machine over the network. It can be omitted when the output is meant for an X server running on the local machine. The display number allows selecting among multiple X servers running on the same machine (Ubuntu uses multiple X servers to enable multiple graphical desktop sessions).

Although the screen number is used to select among multiple physical screen that are managed by the same X server, it is rarely set to anything other than "0" nowadays. Manually setting the "DISPLAY" environment variable's value is rarely needed nowadays since it can be automatically and intelligently adjusted by many applications such as "GDM" and "SSH" when needed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.