How to Print Temporary Environment Variable using Power Shell in Microsoft Windows

Posted on

How to Print Temporary Environment Variable using Power Shell in Microsoft Windows

Printing environment variable which temporarily exist in the Power Shell is a possible action in Microsoft Windows Power Shell. In other words, as the temporary definition of the environment variable still exist in the screen of the Power Shell without having it turned off, it is possible. Basically, the print command will be able to detect the environment variable’s value because it still exist in it. So, it will not have any difficulties finding the value of the environment variable.

Table of Contents

Introduction

As for the short explanation about this article. It just explain how to print an environment variable. Specifically, a temporary environment variable. It is temporary because the process for defining exist in the Power Shell with a certain syntax command. So, it will only available temporarily. When the Power Shell is shut or is closed, the environment variable also simultaneously gone. Printing it back in a new running Power Shell without defining it first will not possible.

How to Print Temporary Environment Variable using Power Shell in Microsoft Windows

For achieving the demonstration of printing temporary environment variable, below are the steps in order :

  1. Running the Power Shell will be the first step. Normally, just run in by pressing the Start button to display the textfield search. Type ‘Power Shell’ in it to search the Power Shell application.

  2. Just click the link pointing to the Power Shell application where it will exist as one of the search result if the Power Shell application exist in the device. It will run the Power Shell with the following appearance :

    How to Print Temporary Environment Variable using Power Shell in Microsoft Windows
    How to Print Temporary Environment Variable using Power Shell in Microsoft Windows
  3. For printing a temporary environment variable, below is the pattern or the format for doing it :

    echo $ENVIRONMENT_VARIABLE_NAME

    As example of the above command usage, it need to be preceded by defining an environment variable first. So, just printing the environment variable directly before defining it will end in an empty output. Below is the execution of it without defining the environment variable before :

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
    
    PS C:\Users\Personal>echo $GITLAB_HOME
    PS C:\Users\Personal>
    

So, as it is shown above, there is no output printed. The reason is because there is no prior definition or setting of an environment variable with the name of ‘$GITLAB_HOME’.

In the previous section, printing a temporary environment variable directly will only print nothing. So, before printing it, just define or set it first. Below are the actual step for printing the environment variable by having to define it first :

  1. As the Power Shell running, just type the following command to define or to set an environment variable :

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
    
    PS C:\Users\Personal>$GITLAB_HOME="C:\Users\Personal\Documents\Gitlab"
    
  2. Following after, just print it. Just pay attention that it must be exactly the same environment variable. If it is not, it will just print nothing. Below is the execution of the command :

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
    
    PS C:\Users\Personal>$GITLAB_HOME="C:\Users\Personal\Documents\Gitlab"
    PS C:\Users\Personal>echo $GITLAB_HOME
    C:\Users\Personal\Documents\Gitlab
    PS C:\Users\Personal>
    

For another demonstration about the usage of Power Shell for printing temporary environment variable, just check this link. For another option, just check out the video below :

Leave a Reply