In the very beginning of a script stands:

if [ -z $DISPLAY ]

I understand, that

  • $DISPLAY holds the value of which pseudo-terminal one is attached to
  • [ -z $DISPLAY ] tests whether $DISPLAY has a value or is an empty string

What is the purpose of $DISPLAY keeping a value, what is different when it has an empty string? Why would it be crucial for the further execution of the script to know whether [ -z $DISPLAY ] is true or false ?

  • I was going to say something about the variable being unquoted, but then I realized that, horrible as it is, it actually works even without quotes (as long as $DISPLAY expands to at most one word of course)
    – ilkkachu
    May 27, 2017 at 18:09
  • I do not understand, can $DISPLAY have more values divided by space characters, because I thought one can only be connected to one pts ?
    – sharkant
    May 27, 2017 at 19:17
  • 2
    I meant that test in general, not specially with DISPLAY. I don't think it usually contains more than one word, but of course someone could set it to anything. Also, it's about X, not pseudoterminals.
    – ilkkachu
    May 27, 2017 at 19:25
  • maybe I am wrong, I only read one source about it, which i can not estimate for adequacy. however I read, that $DISPLAY contains, if set the symbol for a pseudoterminal, mostly 0:0.0 , please correct me
    – sharkant
    May 27, 2017 at 19:44
  • @sharkant Please see askubuntu.com/a/432257/963 May 27, 2017 at 22:50

1 Answer 1


Whatever this script is, it's using the $DISPLAY value to determine if it's running in an X11 environment or not (if the script is running in e.g. a desktop environment, $DISPLAY will be set). It doesn't care about the actual value at all.

  • If it is running in X11, it sets DIALOG to Xdialog, which presumably is a X11 program for displaying dialog boxes.

  • If it's not running in X11 (for example, it's on a headless machine or in an SSH-session), it sets DIALOG to dialog, which presumably is a curses (or at least text-based) program for displaying dialog boxes.

Later, the script may use $DIALOG to display a dialog box appropriate for the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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