Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNIX, get environment variable

I have a ridiculous question due to a ridiculous problem.

Normally if I want to get the contents of an environment variable in UNIX shell, I can do

echo ${VAR} 

Let's assume, due to my ridiculous situation, that this isn't possible.

How do I get the contents of an environment variable to stdout, without someone who is looking at the command itself (not the output), see the value of the environment variable.

I can picture the solution being something like echo env(NAME_OF_VAR) although I can't seem to find it. The solution has to work in sh.

PS I can't write a script for this, it must be a built in unix command (i know, ridiculous problem)

Thanks (and sorry for the absurdity)

like image 280
Mike Avatar asked Mar 19 '10 13:03

Mike


People also ask

How do I find environment variables in Unix?

Unix uses command " printenv " (print environment) or " env " to list all the environment variables.

How do I get environment variables?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.

What is Unix env variable?

What Is a UNIX Environment Variable? UNIX environment variables are variables that apply to both the current shell and to any subshells that it creates (for example, when you send a job to the background or execute a script).


1 Answers

You can do:

printenv VARIABLE_NAME

like image 70
2 revsuser184968 Avatar answered Oct 16 '22 08:10

2 revsuser184968