Page 1 of 1

environment variables

Posted: Tue Sep 02, 2008 1:36 am
by tom
Howdy guys,

I just wanted to point something out.

Code: Select all

(bash)
$ echo $USER
me

$ echo $HOSTNAME
the-name

(newlisp)
(env "USER")
me

(env "HOSTNAME")
nothing
And the hostname is not "nothing" :-) ("env" doesn't return anything) Why is this?

Posted: Wed Sep 03, 2008 7:25 pm
by pjot
Which version of newLisp are you using? Because in my Linux environment:
peter[~]$ echo $USER
peter
peter[~]$ echo $HOSTNAME
solarstriker.thuis.nl
peter[~]$ newlisp
newLISP v.9.4.5 on Linux IPv4, execute 'newlisp -h' for more info.

> (env "USER")
"peter"
> (env "HOSTNAME")
"solarstriker.thuis.nl"
>
...it works as advertised....?

Peter

Posted: Wed Sep 03, 2008 8:44 pm
by cormullion
I don't think it works on all platforms...

Code: Select all

$ echo $HOSTNAME 
imac.local
$ newlisp
newLISP v.9.4.5 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.
> (env "HOSTNAME")
nil

Posted: Thu Sep 04, 2008 3:45 am
by tom
newLISP v.9.4.8 64-bit on Linux IPv4 UTF-8

Posted: Thu Sep 04, 2008 5:38 am
by DrDave
cormullion wrote:I don't think it works on all platforms...
It's probably not a matter of not "working", but simply not being defined on all platforms. HOSTNAME is not a default environment variable on WIN XP, for example.

But if your platform doesn't have it, you can always define it yourself.

Posted: Thu Sep 04, 2008 11:45 am
by Lutz
Its also a matter of what is passed on from the environment to the newLISP process. E.g. on Mac OS X HOSTNAME is defined when in the shell but not inside newLISP. But 'exec' can be used to still retrieve it on Unix:

Code: Select all

> (env "HOSTNAME")
nil
> (exec "echo $HOSTNAME")
("lutzmacmini")
> 
On BSD like Unices like Mac OS X use the man-page for environ to find out what is available at the shell prompt:

Code: Select all

$ man environ

environ is a C variable maintained by the OS and used inside newLISP to read the environment. On Windows the same C variable is maintained.