How to trick a program into thinking there is no X server running

Unix & Linux Asked by Luka Aleksić on November 29, 2020

I have this program that can run with both a text user interface and a graphical user interface.

It lacks any command line switch to force one or the other, rather I guess it somehow auto-detects whether we are in X or not (e.g. if I run it from a virtual terminal it enters its text mode, and if I run it from an X terminal emulator it opens a separate graphical window).

I’d like to force it into text mode and have it run inside the X terminal. How would I go about doing it?

2 Answers

Usually just


in command-line of the terminal. Some applications are smarter than that, and actually check permissions and type of the console versus pseudoterminal.

Correct answer by Thomas Dickey on November 29, 2020

If you want to disable X for a single command you can write

DISPLAY= ./my_command

Notice the strategical blank space after =. More generally, you can set environment variables for a process by prefixing your command with a sequence of <variable>=<value> separated by spaces. Since space serves as separator, = immediately followed by a space clears the preceding variable. We can look at the effect of these prefixes by using a subshell as the command and then printing its environment. Take for instance:

$ A=a B=b C= D=d sh
$ echo $A $B $C $D

This will print

a b d

This shows that the environment of the subshell indeed is different as intended. Note that shell substitution happens before the individual arguments are passed to echo. This means that echo will be called with three arguments and so there's only a single space between b and d in the output, just as if the command line were echo a b d (even though there are two spaces before d it only prints single spaces), but unlike echo a b "" d (which prints two spaces between b and d).

Answered by tobi_s on November 29, 2020

Add your own answers!

Related Questions

Set permanent environment variable for all shells

0  Asked on October 31, 2021 by user14492


How does jq work with keys containing slash?

1  Asked on October 31, 2021 by fhcat


GRUB not showing up in Pop!_OS

1  Asked on October 31, 2021


Set scale for bc inside a variable

1  Asked on October 31, 2021 by mdem7705


partition size vs file system size

1  Asked on October 31, 2021 by fa7eme


Explanation for “Killed Process”

1  Asked on October 31, 2021 by althor


tracking list of installed packages with git

2  Asked on October 31, 2021 by 400-the-cat


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir