[svlug] couldn't connect to display ":0.0"

William R Ward bill at wards.net
Tue Sep 7 10:34:33 PDT 2004


David E. Fox writes:
>On Wed, 01 Sep 2004 23:25:36 -0600
>"skip evans" <skipevans2004 at hotmail.com> wrote:
>> set DISPLAY=192.168.1.101:0.0
>
>Minor point - that won't accomplish much. You want to
>use "export" instead. This is one thing that threw me for a loop when
>I first started using Unix, having come from a DOS environment, you
>see "set" and expect it to work the same (or at least I did); well,
>not exactly.

DOS has only environment variables, so "set X=Y" works fine there.
But Unix shells have both shell variables (accessible only within the
shell itself) and environment variables (accessible in the shell as
well as child processes that are launched from the shell).

But the syntax you use for setting shell and environment variables
depends on what shell you are using.  There are two families - those
based on the Bourne shell such as bash and those based on the C shell
such as tcsh.  The default shell in most Linux distributions is bash,
but some of us (like me) prefer tcsh for command-line work.

In csh/tcsh, it's pretty symple: you set an environment variable with
"setenv X Y" and a shell variable with "set X=Y".  So "set X=Y" is
setting a csh/tcsh shell variable, which won't work here, as shell
variables are not inherited by sub-processes.

But if bash is used (or another Bourne-family shell), things are a
little more complicated.  The syntax to set any variable, whether it
is a shell or environment variable is "X=Y" without any kind of "set"
command.  ("set" is used to set runtime options like "set -x".)  But
whether a variable is a shell or environment variable depends on
whether it has been "exported".  To export a variable use the "export"
command: for example "export X" changes X into an environment
variable.  So you would say "X=Y; export X" to set the environment
variable in a Bourne type shell.  Newer Bourne shells like bash allow
you to combine this into one line, "export X=Y".

If DISPLAY already has a value at all, it's almost certainly already
an environment variable, so merely "X=Y" will work.  If DISPLAY is
unset, then you will have to export it.  Since there's no harm in
exporting something multiple times, "export X=Y" will always work.

So, to summarize, csh/tcsh users would do this:
	setenv DISPLAY 192.168.1.101:0.0

while Bourne-family shell users would do this:
	DISPLAY=192.168.1.101:0.0
	export DISPLAY

or, in most modern versions such as bash:
	export DISPLAY=192.168.1.101:0.0

but if DISPLAY is already set, you could do this and it would work:
	DISPLAY=192.168.1.101:0.0

--Bill.

-- 
William R Ward               bill at wards.net             http://bill.wards.net
-----------------------------------------------------------------------------
"Where a calculator like the ENIAC is equipped with 18,000 vacuum
 tubes and weighs 30 tons, computers in the future may have only 1,000
 vacuum tubes and perhaps weigh 1 1/2 tons." - Popular Mechanics, ca. 1947




More information about the svlug mailing list