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
).
DISPLAY=:0
if it's unset. I believe you can fix that by running it under a different user and using iptables to drop loopback X11, but that's pretty gross. – Kevin Oct 21 '18 at 19:21DISPLAY=invalid:0
? – sourcejedi Oct 21 '18 at 19:57xterm
knows to fail near-instantly on NXDOMAIN. – sourcejedi Oct 21 '18 at 23:18(unset DISPLAY; emacs foo.c)
to do the unset in a subshell for one command or list of commands. – Peter Cordes Oct 22 '18 at 06:52env
instead of a subshell:env -u DISPLAY emacs foo.c
– pabouk - Ukraine stay strong Oct 22 '18 at 11:19emacs
does have a command line flag to disable the use of X. Just typeemacs -nw
. But if it didn't, you could instead useDISPLAY= emacs
, which works as well. – kasperd Oct 22 '18 at 11:34DISPLAY=0.0.0.0:0
fails instantly without doing a name server lookup. – pts Oct 22 '18 at 12:08DISPLAY=:6
if you have problematic software, assuming that display doesn't exist locally. – Julian Goldsmith Oct 22 '18 at 15:13/tmp/.X11-unix/X0
). – marcelm Oct 22 '18 at 18:30