The DISPLAY:= variable

Mikkel L. Ellertson mikkel at
Sat Apr 15 00:17:51 UTC 2006

Al Sparks wrote:
> I saw a script that included the following:
>    #!/bin/bash
>    if test ${DISPLAY:=}x = "x" ; then
>      DISPLAY="mymachine:1.0"
>      export DISPLAY
>    fi
> Now if the variable DISPLAY:= doesn't exist, or is an empty string,
> then the above test is true.
> But what's the point of the test?  It must be an X-Windows thing (or
> kludge?) that in some way uses the DISPLAY:= (not the DISPLAY)
> variable.
>    === Al
This may help explain it. (From man bash.)

    Assign Default Values. If parameter is unset or null, the
    expansion of word is assigned to parameter. The value of
    parameter is then substituted. Positional parameters and
    special parameters may not be assigned to in this way.

I would have expected the format to be:

if test ${DISPLAY:=x} = "x" ; then

In any case, := has special meaning, so DISPLAY and not DISPLAY:= is
actually what is being tested and set.


  Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

More information about the users mailing list