| by Arround The Web | No comments

Windows Equivalent of export Command

The export command is based on Linux and Unix and can only be run from the Linux/Unix command line. However, the “setx” and “set” commands in Windows Command Prompt are identical to the Linux export command. It is utilized to set environment variables permanently or temporarily.

The export command is used to set variables and functions that will be used to set child processes in the new Linux shell.

In this article, we will demonstrate various methods that are identical to the windows equivalent of the export command.

Windows Equivalent of export Command in Command Prompt

The “setx” command can be utilized in Windows Command Prompt to set environment variables permanently. However, in order to set environment variables just for a session or temporarily, utilize the “set” command.

This section lists various examples to practice “setx” and “set” commands in windows.

How to Use the setx Command to Set Environment Variables Permanently?

The setx command is used to set environment variables permanently without impacting previously set environment variables. The syntax of the setx command is provided below:

Syntax

setx path %path%;<path of the variable>

In the above-provided syntax, the “setx” command will set the environment variable permanently. The “path” is the name of the property, “%path% will prefix path to the newly specified directory.

Example
Let’s suppose we want to set the Path environment variable to access Python from the command line. First, open the directory where the “python.exe” file exists and copy the path of the directory from the “Address bar”:

Next, type “CMD” in the “Startup” menu, and open Command Prompt from appeared results as follows:

After that, utilize the “setx” command along with the variable name and value to store the environment variable. As we have set the “Path” environment variable of Python:

> setx path "%PATH%;C:\Python310"

Utilize the below-given command to view Path environment variables:

> set path

The “set” command will show all environment variables and their value. Therefore, we have used the “path” option to filter out only Path environment variables:

From the output, it is observed that the newly added environment variable is added at the end of the list.

How to Utilize the set Command to Set Environment Variable Temporarily?

As discussed earlier, the “set” command can be used to set the environment variables temporarily.

That variable will be available for the current session only. The following syntax refers to using the “set” command in windows:

Syntax

set path %path%;<path of the variable>

The “set” command will set the environment variable temporarily or for a single section.

Example
Open the command prompt from the start-up menu. Type the following command, which will set the environment variable. The “path” is a property that we want to set. Then specify the path of the variable. As we have set a Path environment variable for Python:

> set path "%PATH%;C:\Python310"

Here you go! You have learned various commands to set environment variables in Windows.

Conclusion

The export is a Linux-based utility to set the environment variables. The Windows equivalent of the export command is the “setx” command or the “set” command. The “setx” command is utilized to set environment variables permanently. However, the “set” command can set variables temporarily (for one session only). In this blog, we have demonstrated the Windows equivalent command of the Linux export command.

Share Button

Source: linuxhint.com

Leave a Reply