environment variables

Started by tom, September 01, 2008, 06:36:54 PM

Previous topic - Next topic

tom

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?

pjot

#1
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

cormullion

#2
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

tom

#3
newLISP v.9.4.8 64-bit on Linux IPv4 UTF-8

DrDave

#4
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.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.

\"Getting Started with Erlang\"  version 5.6.2

Lutz

#5
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.