102-500 · Question #206
Which of the following lines is an example of a correct setting for the DISPLAY environment variable?
The correct answer is B. hostname:displaynumber. See the full explanation below for the reasoning.
Question
Options
- Ahostname:displayname
- Bhostname:displaynumber
- Chostname/displayname
- Dhostname/displaynumber
- Ehostname
How the community answered
(69 responses)- A7% (5)
- B75% (52)
- C1% (1)
- D3% (2)
- E13% (9)
Community Discussion
7B is the one you want. The DISPLAY variable uses a colon separator between the hostname and the display number, like hostname:0 or hostname:0.0, because that is the X Window System syntax and the number refers to which display server instance to connect to, not a name.
Imani has it right on the colon syntax, though worth noting that when you are connecting locally the hostname part is usually omitted entirely so you will just see :0 or :0.0, which trips people up the first time they run echo $DISPLAY on a local desktop versus an SSH session.
The format is hostname:displaynumber, so B is the one they want. A trips people up because "displayname" sounds plausible if you have never actually set DISPLAY by hand, but X uses numbers, not names, so you end up with something like :0 or mybox:0.0 where the second number after the dot is the screen number. The slash variants C and D are just wrong, DISPLAY uses a colon as the separator. E might work in some shorthand context locally but it is not a correct full example of the variable format.
Yeah, the only thing worth adding is that on a box with just one screen you almost never see the .0 in practice even though it is technically implicit, which can make people think the screen number is optional when really the default just quietly fills it in.
I almost went with A because "displayname" sounded like something you'd set for a named session, but then I remembered the DISPLAY variable uses a numeric identifier for the display, not a name, so the format is hostname:displaynumber, which locks in B.
D has to be right because the slash separates the host from the display identifier just like a file path does, and the term "displaynumber" matches the actual numeric value X uses internally, so hostname/displaynumber fits both the syntax and the naming convention perfectly.
The colon is the actual separator in X display syntax, not a slash, so hostname:displaynumber is the correct form and that is what B shows. The slash reading makes sense intuitively but the X protocol spec is specific about using a colon there.