Tag: environment variables

  • Linux Tutorial Series – 83 – Modifying environment variables

    Here is the video version, if you prefer it:

    If you ever want to modify environment variables (and you may sometimes) or some tutorial you find on the World Wide Web advises you to do so, it is useful to know what is going on.

    When modifying environment variables, you are, in most cases, adding something to already existing environment variables. Here is how to do it: (modeled after (Ward, 2014)⁠)

    mislav@mislavovo-racunalo:~$ printenv | grep VARIABLE

    mislav@mislavovo-racunalo:~$ VARIABLE=value

    mislav@mislavovo-racunalo:~$ export VARIABLE

    mislav@mislavovo-racunalo:~$ printenv | grep VARIABLE

    VARIABLE=value

    The commands we are focusing on here are VARIABLE=value and export VARIABLE. Those commands introduce a new variable named VARIABLE with the value value and export VARIABLE places variable VARIABLE in the environment.

    The changes you just made to your environment are non-permanent. Meaning, when you close your Terminal window, the variable VARIABLE will disappear from the environment. There is a way to make these changes permanent, but it is a topic for another post.

    Hope you learned something useful!

    References

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 21-22

  • Linux Tutorial Series – 81 – Environment variables

    Here is the video version, if you prefer it:

    Today we will talk about a special kind of operating system variables. As we already know, the operating system (and other computer programs) use variables, which are places in computer memory that store values relevant to a computer program. A special kind of operating system variables are environment variables. Let’s explain what “environment variables” mean.

    Environment variables are the variables that the operating system passes to your shell programs. (Ward, 2014)⁠ What that means is that when you run your shell program, it has access to the environment variables. A shell program then uses those environment variables to read its configuration and options from them.

    Here are some examples of environment variables I got by running printenv, which is used to print all (or a part of) your environment. (“PRINTENV(1),” n.d.)⁠

    mislav@mislavovo-racunalo:~/Linux_folder$ printenv

    SHELL=/bin/bash

    SESSION_MANAGER=local/mislavovo-racunalo:@/tmp/.ICE-unix/6698,unix/mislavovo-racunalo:/tmp/.ICE-unix/6698

    ...

    Here we can see SHELL and SESSION_MANAGER as names of my environment variables, while the strings right of the equal sign are the values of the variables.

    Takeaway: Environment variables are passed by the operating system to your shell programs and they store configuration and options that shell programs take into account when they are executed.

    Hope you learned something useful!

    References

    PRINTENV(1). (n.d.). Retrieved February 7, 2020, from http://man7.org/linux/man-pages/man1/printenv.1.html

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 21-22