Team SET used to view and change environment variables in the command line Windows line. Environment variables are variables whose accepted values ​​characterize the environment in which the current program- ways system files, hardware information, user directories, etc. Environment variable values ​​are generated during the process Windows boot, user registration in the system, when executing individual processes or using a command SET. To view the value assumed by a specific variable, you can use the command:

SET variable
SET PATH- display the value of a variable PATH
To create a new variable or change the value of an existing one, use the command:

SET variable=string

variable- Environment variable name.
line- A character string assigned to the specified variable.

SET MyName=Vasya- set the value of a variable MyName

SET path=C:\progs;%path%- change the value of a variable PATH by adding to the beginning of the line C:\progs

The value accepted by the variable is available for processing in command files by using its name enclosed in percent signs - % . For example, a command to display text on the ECHO display in the form:

ECHO date- will display the word "date" and the command
ECHO %date% will display the value of the variable date, i.e. current date in operating system format.

Team SET without parameters is used to display the current values ​​of environment variables.

ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Usr\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=TEST7
ComSpec=C:\windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Usr
LOCALAPPDATA=C:\Users\Usr\AppData\Local
LOGONSERVER=\\TEST7
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\windows\system32;C:\windows;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS; .VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 3 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0304
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\windows\system32\Windows PowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SystemDrive=C:
SystemRoot=C:\windows
TEMP=C:\Users\Usr\AppData\Local\Temp
TMP=C:\Users\Usr\AppData\Local\Temp
USERDOMAIN=test7
USERNAME=Usr
USERPROFILE=C:\Users\Usr
windir=C:\windows

In addition to the variables displayed in the list when calling the SET command, there are others whose values ​​change dynamically:

%CD%- takes the value of the current directory.
%DATE%- takes the value of the current date.
%TIME%- takes the value of the current time.
%RANDOM%- meaning random number in the range between 0 and 32767.
%ERRORLEVEL%- the current value of ERRORLEVEL, a special variable that is used as an indication of the result of program execution.
%CMDEXTVERSION% CMD.EXE extended command processing version value.
%CMDCMDLINE%- expands to the original command line that called the shell.

If you specify only part of the name when calling the SET command, a list of variables whose names begin with the specified string will be displayed. For example:

SET U- will display the values ​​of all variables whose names begin with "U".

The SET command supports two additional switches:

SET /A expression

SET /P variable=

The /A switch specifies that the string to the right of the equals sign is a numeric expression whose value is being evaluated. The expression engine is very simple and supports the following operations, listed in descending order of priority:

When using any logical or binary operators, you must enclose the expression string in quotation marks. Any non-numeric strings in the expression are treated as environment variable names whose values ​​are converted to numeric form before use. If a variable with the specified name is not defined in the system, a null value is substituted instead. This allows you to perform arithmetic operations with environment variable values, without having to enter % signs to get the values. If the SET /A command is called from command line, not from batch file, it outputs the final value of the expression. The name of the environment variable must appear to the left of any assignment operator. Numeric values ​​are treated as decimal unless they are preceded by a prefix:

0x- for hexadecimal numbers
0 - for octal numbers.

Example of using prefixes:

SET /A REZ=0xA+012
ECHO %REZ%

In this batch file, the value of the variable is REZ is calculated by adding the number 10 represented in hexadecimal (0xA) and the number 10 represented in octal (012).

The /P switch allows you to set the value of a variable for the input string entered by the user. Shows the specified promptString prompt before reading the entered string. The promptString prompt may be empty. This key allows you to organize a dialogue with the user in a batch file:

@ECHO OFF
SET /P NAME=Enter username:
SET /P pass=Enter password:
ECHO Username - %NAME% , Password - %PASS%

In batch files, quite often you need to work with part of the value taken by a variable, for which you use substitution values:

variable:string1=string2- replaces in the received value of the variable line1 on line2

Next batch file uses replacing the dot character with a dash character in the variable value corresponding to the current date:

@ECHO OFF
set tm=%DATE%
ECHO Date1 = %tm%
SET tm=%DATE:.=-%
ECHO Date2 = %tm%

To highlight part of the value taken by a variable, the following construction is used:

variable:~x,y- Where x- the number of skipped characters from the beginning of the line, and y- the number of characters used as the value of the variable.

The following example uses the display of the current time without seconds and fractions of seconds (only the first 5 characters from the standard value of the TIME variable):

@ECHO OFF
set tm=%TIME%
ECHO Time1 = %tm%
SET tm=%TIME:~0.5%
ECHO Time2 = %tm%

If the value y(length) is not specified, then the value of the variable remaining until the end of the line is used. If the value y is negative, then part of the variable value string from the end is used. The previous example can be modified to specify that the time value received is stripped 6 characters from the end:

@ECHO OFF
set tm=%TIME%
ECHO Time1 = %tm%
SET tm=%TIME:~0.-6%
ECHO Time2 = %tm%

It is possible to use the number of gaps is not specified, and a negative number is used, then the received value will be part of the variable from the end of the line:

%PATH:~-10%- will extract the last 10 characters of the PATH variable

You can omit the null value while maintaining the substitution format:

%PATH:~0.-2% equivalent %PATH:~,-2%

When using environment variables in command files, there is a certain limitation associated with the fact that the assigned value remains unchanged when it is modified within a group of commands specified by parentheses, for example in commands IF or FOR. To bypass this limitation use the command processor launch with the /V:ON parameter and instead of percent signs to obtain the received value variable, are used exclamation marks. In addition, it is possible to use the standard shell launch, but with local inclusion this mode command:

The difference in the results of using variable values ​​is quite clearly demonstrated by the following batch file:


@ECHO OFF
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo With percent sign=%VAR% , With question mark=!VAR!

Team set VAR=after executed inside a subroutine delimited by parentheses and, if the command is removed Setlocal EnableDelayedExpansion or not to use to get the value of a variable VAR exclamation marks, its value will remain the old one (what was set before entering the subroutine). A similar problem occurs when the value of a variable is changed within the command loop. FOR. For example, to get a list of files in the current directory, a batch file like this won't work:

set LIST=
for %%i in (*) do set LIST=%LIST% %%i
echo %LIST%

Variable value LIST will not be changed inside the loop. In order for this to happen, the batch file needs to be modified as follows:

Setlocal EnableDelayedExpansion
set LIST=
for %%i in (*) do set LIST=!LIST! %%i
echo %LIST%

Now, the value of the variable LIST inside a loop FOR will change, sequentially taking on the values ​​of file names separated by space ( set LIST=!LIST! %%i)

This section concerns:
  • Platforms: Solaris SPARC, Red Hat Linux, SUSE Linux, Oracle Linux, Windows 10, Windows 8, Windows 7, Vista, Windows XP, Mac OS X

The instructions on this page are intended only for experienced users and system administrators.


General information

  • Variable PATH is a system variable that the operating system uses to find the desired executable objects on the command line or terminal window.
  • System variable PATH can be set using system utility in the Windows Control Panel or using the Linux and Solaris shell startup file.
  • On computers running Windows or Mac OS X making changes to the PATH system variable usually not required.

Windows

Windows 10 and Windows 8
  1. In the "Search" line, search for: System (Control Panel)
  2. Click on the link .
  3. Click Environment Variables. In chapter Environment Variables Change
  4. In the window (or New system variable OK OK.
Windows 7
  1. On the desktop right click click on the icon Computer.
  2. IN context menu select Properties.
  3. Click on the link Advanced System Settings.
  4. Click Environment Variables. In chapter Environment Variables select the PATH environment variable. Click Change. If the PATH variable does not exist, click Create.
  5. In the window Changing a system variable(or New system variable) specify the value of the PATH environment variable. Click OK. Close other open windows by clicking OK.
  6. Reopen the command prompt window and run the java code.
Windows XP
  1. Click Start, select Control Panel, double click on System and select a tab Additionally.
  2. Click Environment Variables. In chapter Environment Variables select the PATH environment variable. Click Change. If the PATH variable does not exist, click Create.
  3. In the window Changing a system variable(or New system variable) specify the value of the PATH environment variable. Click OK. Close other open windows by clicking OK.
  4. Reopen the command prompt window and run the java code.

Mac OS X

To run another version of Java, provide the full path or use the java_home tool:

% /usr/libexec/java_home -v 1.8.0_73 --exec javac -version

Solaris and Linux

  1. To see if the path is configured correctly:
    In terminal windows, enter:
    % java -version
    The version of the java tool will be displayed if it cannot be found. If the version is outdated or an error appears java: command not found, then the path is set incorrectly.
  2. Determine which executable version of java is the first one found in a variable PATH
    In a terminal window, enter:
    % which java
Final path setup

To set the path permanently, configure it in the startup file.
Note. Instructions are provided for the two most popular shells on Linux and Solaris. If you are using other shells, see the tutorial on setting the PATH variable.

Bash shell

Edit the startup file (~/.bashrc)

  1. Change a variable PATH variable
    PATH=/usr/local/jdk1.8.0/bin:$PATH
    export PATH
  2. Download the startup file
    %. /.profile

  3. % java -version
C shell (csh)

Edit the startup file (~/.cshrc)

  1. Set the path
    set path=(/usr/local/jdk1.8.0/bin $path)
  2. Save changes and close window
  3. Download the startup file
    % source ~/.cshrc
  4. Make sure the path is set by repeating the java command
    % java -version

Instructions

Right-click on the My Computer icon located on your desktop or Start menu. In the context menu that appears, select the bottom line “Properties” - a new “System Properties” window will open. You can also open the System Properties window by pressing the Windows + Pause Break hotkey combination. If you are using the Windows 7 operating system, then also right-click on the “My Computer” icon, select “Properties”, and then select “Advanced system settings” on the left side of the properties window.

In the “System Properties” window, go to the “Advanced” tab by left-clicking on it - you will see three sections additional settings systems. Below them there will be two more buttons - “Environment Variables” and “Error Report”. You need environment variables - click on the appropriate button.

The Environment Variables window contains two categories of variables, one being User Environment Variables and the other being . Find the path variable in the list of system variables and select it by clicking the left mouse button.

Now, with the path variable selected, click on the “Change” button located under the list window - a small “Change system variable” window will open, where two input lines will be located - “Variable name” and “Variable value”. Change the value of the path variable to whatever you want.

Another way to change the value of the path variable is as follows: in the “Environment Variables” window, click on the “Create” button, then in the window that opens, in the “Variable Name” field, enter “path” and in the “Variable Value” field, enter the desired value. This will change the current value of the path variable to the one you just entered.

Video on the topic

An environment variable called Path is used by operating system components and those installed on it. application programs to obtain the addresses of directories in which you can search for executable files. Some addresses are present in this variable by default and the user cannot change them, but he can add (“write”) additional addresses to it.

Instructions

Right-click the “My Computer” icon on the desktop and select “Properties” from the pop-up context menu. The same can be done with the “Computer” item in the main menu of the operating system on the “Start” button. Or you can simply press the win + pause hotkey combination - any of these actions will launch the OS component called “System Properties”.

Go to the “Advanced” tab of the window that opens and click the “Environment Variables” button located at the bottom. Another window will open with two tables placed in it - the operating system installation you need is placed at the top (“User Environment Variables”). Select the line that has the word Path in the “Variable” column, and then click the “Edit” button under this table. As a result, a third and final dialog box will open with the title “Changing a user variable” and two fields to fill out.

Enter the desired path in the “Variable value” field. If it already contains any entry, then add a new one to the right, separating it from the existing one with a semicolon (;). In order not to make a mistake in writing the full address to the desired directory, it is better to copy the path to it in Windows Explorer- open it (win + e), go to the desired folder, highlight the full path to address bar file manager (ctrl + a), copy (ctrl + c), return to the dialog box and paste the contents of the clipboard (ctrl + v) into the “Variable value” field.

Leave the value in the “Variable Name” field unchanged (Path should remain there) and click OK. After this, successively press the same OK buttons in the other two open windows. This completes the procedure for adding a new value to the Path variable.

Video on the topic

All Nokia mobile phones are made on the S40 and S60 platforms. This means that java machines are automatically integrated on them. Therefore, to install a J2ME application on such a phone, you just need to copy it to the phone's built-in memory or to a memory card.

Instructions

Launch your internet browser mobile phone Nokia to deliver java. You need to download the JAR file. For other phones, you would also need to download the JAD file. However, due to the greater demand for this particular file type, it will be easier for you to download it.

Please note that automatically, along with the JAD file, a JAR file will also be downloaded to your phone. Use the phone's built-in browser if it is based on the S40 platform. This is necessary so that after downloading the file will be automatically installed. Those. installing Java is no longer necessary. Go to the "Games" or "Applications" section. In the list of programs you will just find installed file.

Do the following to install the Java application if yours has a memory card. Turn off your phone. Remove the memory card from it. Take a card reader. Use it to connect your phone memory card to your computer. Copy all the Java applications you are interested in to the appropriate folder. After this, remove the memory card correctly and insert it into the phone.

Do the following if your phone is based on the S60 platform. Launch your mobile phone's built-in browser. Download required file JAR or JAD format. You can also use a third-party browser, such as Opera Mobile, Opera Mini or some other. The thing is that the built-in browser will automatically save the file to the UCDownloaded folder, and with a third-party browser you can set any folder as the save location on the memory card of your mobile phone.

For correct installation, remove the memory card from your mobile phone. Using a card reader, connect it to your personal computer. Then install JAR file to the applications folder on the memory card. The installation does not take long and should not cause any complications. After it is completed, remove the memory card and insert it into the phone.

The operation of setting an environment variable can be performed by the user standard means operating system Microsoft Windows and does not involve the involvement of additional software third party developers.

When the operating system starts a program, it starts a new process and somehow passes it information about the settings of the environment, or environment (in English language the term environment is used). This information consists of a set of variables containing some values. A process can obtain these values ​​by accessing the desired variable by name. For example, to find out where the directory is that the operating system recommends to use for storing temporary files, you need to get the value of the TEMP environment variable.

How can I view the values ​​of environment variables?

IN Windows console you can see the value of this variable by running the command echo %TEMP% , in the PowerShell console you need to run the command echo $Env:TEMP , and in Linux consoles or MacOS - echo $TEMP command.

If you are writing a program in a language Python programming, the value of this variable can be obtained like this:

import os temp = os . environ["TEMP"]

IN Java language this can be done like this:

String temp = System . getenv(). get("TEMP");

In C#, a similar action looks like this:

string temp = System . Environment. GetEnvironmentVariable("TEMP");

What does the PATH environment variable affect?

Using environment variables, you can transfer information not only to launched processes, but also to the operating system itself. It also reads and uses the values ​​of environment variables, so you can control some aspects of the operating system's behavior by changing environment variables.

The PATH variable contains a list of directories in which the operating system tries to search for executable files if the user did not explicitly specify the path to the desired executable file at startup.

Let's imagine that a computer running Windows has two different versions Python programming language interpreter. This can be done by installing them in different directories, for example, C:\Python27 and C:\Python34. The executable file for both versions is called python.exe.

In order to run the executable file of the desired version, you can specify the full path to it, for example, C:\Python34\python.exe:

But I’m too lazy to indicate the full path every time, and I also have to remember it.

An alternative is to add the path to the directory where this executable file is located to the PATH environment variable, and then you can run it by specifying only the name. And to find out where it is (according to the operating system) it is located, you can use the where command in the operating system Windows system or the which command in the Linux or MacOS operating system.

This variable contains a list of directories in which the operating system should look for executable files. The separator is a semicolon (;) in the Windows operating system and a colon (:) in operating systems Linux and MacOS.

Please note that in the PATH variable you need to add not the paths to the executable files, but the paths to the directories where they are located!

PATH Variable and Utility Programs

It is not necessary to add the paths to all directories in which executable files are located on your computer to the PATH variable. Most likely, you launch most programs “through the start menu.” The PATH variable has no effect on this launch method. It is important to configure it so that you can quickly and conveniently launch all sorts of small programs from the console.

For example, this variable usually includes the path to the “standard” places where various small utility programs are located. In the Windows operating system this is the directory C:\Windows\system32, in operating systems Linux systems and MacOS directory /usr/bin .

It is thanks to this that we can, for example, use the find utility in the Windows console to search for files or the telnet utility to establish a remote connection using the protocol of the same name, simply by specifying their name, and not the full path c:\Windows\system32\telnet.exe .

When you have a new utility program, the question arises - where to put it? On the one hand, it can be placed in C:\Windows\system32 or /usr/bin . But if you don't like to litter standard directories, then make some special directory, put all such small programs in it, and add the path to this directory to the PATH environment variable.