How to trick a program into thinking there is no X server running
Usually just
unset DISPLAY
in command-line of the terminal. Some applications are smarter than that, and actually check permissions and type of the console versus pseudoterminal.
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
).