PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] why does a simple print(os.getenv("HOME")) get nil?

 August 21, 2022     environment-variables, lua, null     No comments   

Issue

I'm a total newbie and I don't get why this doesn't work, anyone knows what's happening?.

I'm following a tutorial and just to clarify, it is only a print(os.getenv("HOME"))


Solution

How to solve this:

print(os.getenv("HOME")) prints nil. So os.getenv("HOME") must return nil.

In which cases does os.getenv return nil? Let's refer to the Lua manual:

https://www.lua.org/manual/5.4/manual.html#pdf-os.getenv

os.getenv (varname)

Returns the value of the process environment variable varname or fail if the variable is not defined.

fail equals nil. Lua < 5.4 returns nil.

So looks like HOME is an undefined process environment variable.

Should it be defined? What is HOME to begin with?

Let's google "environment variable home" and among the first few hits we see:

https://superuser.com/questions/607105/is-the-home-environment-variable-normally-set-in-windows

We are running Windows, otherwise we wouldn't be here in the first place so let's run print(os.getenv("UserProfile")) and we have success.



Answered By - Piglet
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing