environment variables

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
tom
Posts: 168
Joined: Wed Jul 14, 2004 10:32 pm

environment variables

Post 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?

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post 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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post 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

tom
Posts: 168
Joined: Wed Jul 14, 2004 10:32 pm

Post by tom »

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

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Post 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.
...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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

Locked