newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: tom on September 01, 2008, 06:36:54 PM

Title: environment variables
Post by: tom on September 01, 2008, 06:36:54 PM
Howdy guys,



I just wanted to point something out.

(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?
Title:
Post by: pjot on September 03, 2008, 12:25:10 PM
Which version of newLisp are you using? Because in my Linux environment:


Quote
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
Title:
Post by: cormullion on September 03, 2008, 01:44:42 PM
I don't think it works on all platforms...


$ echo $HOSTNAME
imac.local
$ newlisp
newLISP v.9.4.5 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.
> (env "HOSTNAME")
nil
Title:
Post by: tom on September 03, 2008, 08:45:34 PM
newLISP v.9.4.8 64-bit on Linux IPv4 UTF-8
Title:
Post by: DrDave on September 03, 2008, 10:38:41 PM
Quote from: "cormullion"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.
Title:
Post by: Lutz on September 04, 2008, 04:45:34 AM
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:



> (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:


$ 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.