DEV Community

Cover image for Linux Commands: printenv
Umesh Yadav
Umesh Yadav

Posted on • Updated on • Originally published at umesh.dev

Linux Commands: printenv

printenv is used to print out the environment variables. Environment variables are a common form of setting global values across a terminal session. Environment variables can be set by the systems, automation scripts, or by the user.

You can print your all environment variables using just printenv.

Screenshot 2020-10-18 at 10.37.02 PM.png

If you want to print the value of a specific variable you can use printenv <variable name>.

Screenshot 2020-10-18 at 10.38.24 PM.png

Conclusion

If you are ever stuck and want to know what was the value of the environment variable you can use it. I have found myself using this quite often when debugging issues in production or on my local machine.

If you liked this post please share it with others so that it can help them as well. You can tag me on Twitter @imumesh18. Also please follow me here and on Twitter for future blogs which I write over here

Latest comments (3)

Collapse
 
michaelcurrin profile image
Michael Currin • Edited

I haven't seen this before. I use env which is similar to printenv

unix.stackexchange.com/questions/1...

View variables.

env
Enter fullscreen mode Exit fullscreen mode

And to search:

env | grep PATH
Enter fullscreen mode Exit fullscreen mode

Or just

echo $PATH
Enter fullscreen mode Exit fullscreen mode

I see you cover env in the next post for modifying environment but not for reading it

Collapse
 
umesh profile image
Umesh Yadav

Hey, yes actually you can grep the output of the env and get the values or echo works as well. Most the people use what you have mentioned above and very few people are aware about printenv and how easy it is to use. That's the only reason wrote about it. Thanks for the feedback on the env blog, I will surely consinder adding more about reading a varibale.

Collapse
 
michaelcurrin profile image
Michael Currin

printenv FOO is longer to type than echo $FOO and also it is less flexible. You can't do something like echo "$FOO $BAR"

Maybe you can make an alias:

alias p=printenv
Enter fullscreen mode Exit fullscreen mode

So you can run

p FOO
Enter fullscreen mode Exit fullscreen mode