Re: The DISPLAY:= variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

${parameter:=word}
    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.

Mikkel
-- 

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


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux