os.env not working as I expected on yun

Posted by Jantje on Thu 14 May 2015 06:05 PM — 3 posts, 15,488 views.

Belgium #0
Hi Nick
As we discussed a long time ago I have been using lua on yun and lately I ported a ash script to lua.
The performance boost is huge!!! So me really happy.
However I bumped in a wierd thing. It seems that environment variables that have been created during on the command prompt before lua is started are not found by lua.

In the following dump DumpFile was created by running a script.

root@Marvin2:/www/cgi-bin/jantje# echo $DumpFile
/tmp/jantje/ttyATH0/dump.txt
root@Marvin2:/www/cgi-bin/jantje# lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio (double int32)
> print(os.getenv("DumpFile"))
nil
> print(os.getenv("HOME"))
/root

As you can see from the log above the OS knows the environment variable DumpFile but Lua does not.

Can you help me out on this one?
Txs
Jantje
Australia Forum Administrator #1
Template:Arduino
Please post Arduino-related questions to the Arduino Forum or to StackExchange: Arduino. This saves splitting questions and answers between this forum and the Arduino ones.


Disclaimer: I don't have a Yun and know nothing about programming them.

Although this looks like a Unix problem. I think scripts have to export environment variables if you want to use them later.

Something like:


export FOO=bar
Belgium #2
Txs
spot on.

root@Marvin2:/www/cgi-bin/jantje# . ./SetGlobalSettings.sh
root@Marvin2:/www/cgi-bin/jantje# echo $DumpFile
/tmp/jantje/ttyATH0/dump.txt
root@Marvin2:/www/cgi-bin/jantje# export DumpFile=${DumpFile}
root@Marvin2:/www/cgi-bin/jantje# lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio (double int32)
> print(os.getenv("DumpFile"))
/tmp/jantje/ttyATH0/dump.txt

I never really understood the concept of export. I think my understanding just increased :-))

Indeed yun is a linux (openwrt)

Jantje