os.execute and bash environment variables

1,519 views
Skip to first unread message

vany...@gmail.com

unread,
Jan 18, 2010, 6:06:15 AM1/18/10
to scite-i...@googlegroups.com
Hi,

I am using latest SciTE on Ubuntu 9.10 64 bit.

I would like to execute this lua command:
os.execute('mkdir /newdir_${HOSTNAME}')
The result is a new directory: /newdir_

It seems that the value of ${HOSTNAME} cannot be retrieved from LUA.
Executing from command line works perfect:
#mkdir /newdir_${HOSTNAME}
New directory created: /newdir_myhost

What could be the issue that I cannot use bash global/environment
variables from LUA?

Thanks
Istvan

Philippe Lhoste

unread,
Jan 18, 2010, 7:10:42 AM1/18/10
to scite-i...@googlegroups.com
On 18/01/2010 12:06, vany...@gmail.com wrote:
> I would like to execute this lua command:
> os.execute('mkdir /newdir_${HOSTNAME}')
> The result is a new directory: /newdir_
>
> It seems that the value of ${HOSTNAME} cannot be retrieved from LUA.

Note: that's Lua (Portuguese common name meaning 'moon') not LUA (Lua is Unlikely to be an
Acronym... :)) Common mistake coming from who know where.

You should try:

os.execute('mkdir /newdir_' .. props["HOSTNAME"])

--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

vany...@gmail.com

unread,
Jan 18, 2010, 7:28:32 AM1/18/10
to scite-i...@googlegroups.com
>os.execute('mkdir /newdir_' .. props["HOSTNAME"])

props["HOSTNAME"] is empty, result is same as before: /newdir_

Thanks
Istvan

Philippe Lhoste

unread,
Jan 18, 2010, 12:57:00 PM1/18/10
to scite-i...@googlegroups.com
On 18/01/2010 13:28, vany...@gmail.com wrote:
> props["HOSTNAME"] is empty, result is same as before: /newdir_

Ah, it works for me on Windows, I supposed it was the same on Linux.

Jeff Pohlmeyer

unread,
Jan 18, 2010, 1:39:43 PM1/18/10
to scite-i...@googlegroups.com
On Mon, Jan 18, 2010, <vany...@gmail.com> wrote:

> I am using latest SciTE on Ubuntu 9.10 64 bit.

> What could be the issue that I cannot use bash
> global/environment variables from LUA?


It looks like bash does not export "HOSTNAME" by default.

print(os.getenv("PATH")) -- works
print(os.getenv("HOSTNAME")) -- fails

You could add "export HOSTNAME" to you ~/.bashrc file,
or put it on the scite command-line:

HOSTNAME=$HOSTNAME SciTE ...

or you could try a script something like:

local hostname="unknown"
local hn=io.popen("hostname")
if hn then
hostname=hn:read("*l")
hn:close()
end

print(hostname)


- Jeff

vany...@gmail.com

unread,
Jan 19, 2010, 2:10:20 AM1/19/10
to scite-i...@googlegroups.com

> print(os.getenv("PATH")) -- works
Works for me too.

> print(os.getenv("HOSTNAME")) -- fails
Fails for me too.

I've lots of variables in ~/.bashrc but they are not visible even they
are exported.

> or you could try a script something like:

It works, thank you.

Regards,
Istvan

Reply all
Reply to author
Forward
0 new messages