Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • 21
    If I go to the terminal and write MYNEWVARIABLE=Ubuntu and execute printenv it doesn't show there. Why is that, and how do those others show up? Commented Mar 30, 2013 at 3:30
  • 8
    Probably you are seeing the difference between a shell variable and an environment variable. Try export MYNEWVARIABLE=Ubuntu and it will work as you expect.
    – Rmano
    Commented Oct 12, 2013 at 0:41
  • 5
    if you simply execute set, it lists the variable created by you as well. Or do set | grep myvar Commented Jan 4, 2015 at 15:01
  • 8
    printenv is an external command, so it only knows about (and prints) exported environment variables. set is an internal bash command, so it shows all the "shell variables" (unexported environment variables) as well as the exported environment variables.
    – Dan Pritts
    Commented Jul 30, 2015 at 15:33
  • 2
    To expand on @Rmano's reply to @Strapakowsky... This will not work unset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW, but this will unset MYNEWVARIABLE; export MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW, and this will unset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu printenv | grep MYNEW. Using export says "the variable I'm setting should be part of the environment that gets passed to processes, not just a variable in this shell." My third example says "the variable should be part of the environment that gets passed to THIS process, but not stick around afterward." Commented Aug 26, 2016 at 17:39