Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

set


May 23, 2021 DOS Command learning manual



set [[/a [expression]] [/p [variable=]] string]


Parameters

/a

Set the string to a numeric expression that can be evaluated.

/p

Set the value of variable to an input line.

variable

Specify the variables that need to be set or modified.

string

Specifies the string to associate with the specified variable.

/?

Show help at the command prompt.

Comments

Use the set in the Recovery Console

The set command has different parameters and is available from the Recovery Console.


Use special characters

The characters are | A special command shell character that must be used in a string before or in quotation marks (i.e., "StringContaining and Symbol"). If you want to use quotation marks to cause a string with special characters, the quotation marks are set as part of the value of the environment variable.


Use environment variables

Use environment variables to control the operation of certain batch files and programs, and how Windows XP and MS-DOS subsysyssors are displayed and worked. The set command is often used in Autoexec.nt files to set environment variables.


Displays the current environment settings

When you type only the set command, the current environment settings are displayed. T hese settings typically contain COMSPEC and PATH environment variables to help find programs on disk. The two other environment variables used by Windows XP are PROMPT and DIRCMD.


Use parameters

When you specify the value of a variable and string, the specified variable value is added to the environment, and the string is associated with the variable. If the variable already exists in the environment, the new string value overrides the old string value.


If you specify only one variable and one equal sign (no string) for the set command, the string value associated with the variable is cleared (as if the variable did not exist at all).


Use /a

The following table lists operators that support /a in order of priority from highest to below.


The operation performed by the operator

Grouping

:: / % - Algorithm

The logical shift

Operations by bit "and"

The operation is "different or" by bit

| O peration by bit or

. |

, the expression separator


If you use logic ( samp; ||) or mode (%) o perator, use quotation marks to raise the expression string. A non-numeric string in an expression is treated as an environment variable name, and its value is converted to a number before it is processed. If you specify an environment variable name that is not defined in your current environment, a zero value is assigned, allowing you to arithmetic the environment variable without having to retrieve the value using %.


If you run set /a from the command line outside the command script, the final value of the expression is displayed.


A value is a hex number, with a prefix plus 0× representing a hex number and a 0 representing an octal number. T herefore, 0×2 is the same as 18 and 022 is the same, and the octal notation is confusing. For example, 08 and 09 are not valid numbers because 8 and 9 are not valid octal numbers.


Use /p

A prompt string is required.


Environment variable extensions that support latency

Deferred environment variable extension support has been added. This support is disabled by default, but can be enabled or disabled using cmd /v.


Use command extensions

When command extension (default) is enabled and set is run separately, all current environment variables are displayed. If you run set with a value, a variable that matches that value is displayed.


Use set in a batch file

When you create a batch file, you can use the set command to create a variable, and then use the number variable %0 U se these variables as well as %9. Y ou can also use %0 The %9 variable is used as input to the set command.


Call the set variable from the batch file.

When a variable value is called from a batch file, it must be enclosed in a percent sign (%) . For example, if the batcher creates an environment variable BAUD, you can type %baud on the command line and use the string associated with the BAUD as a replaceable argument.


Example

To set an environment variable named TEST^1, type:


set testVar=test^^1


To set up an environment variable named TEST and 1, type:


set testVar=test^&1


Set the contents of the variable value after it is set to an equal sign. If you type:


set testVar="test^1"


You'll get the following results:

testVar="test^1"


To set a environment variable named INCLUDE so that the string C:\Inc (the directory of s Inc on drive C) is associated with that variable, type:


set include=c:\inc


You can then pass the percent sign (%) used in the name E nclose INCLUDE and use the string C:\Inc in the batch file. For example, you might include the following command in a batch file to display the directory content associated with an INCLUDE environment variable.


dir %include%


When this command is processed, the string C:\Inc replaces %include.


You can also use set in the batch program to add a new directory to the PATH environment variable. For example:


@echo off

rem ADDPATH. B AT adds a new directory

rem to the path environment variable.

set path=%1; % path%

set


When the command expression (default) is enabled and a value is used to run the set, variables that match that value are displayed. For example, if you type set p in the command prompt, you will get the following results:


Path=C:\WINNT\system32; C :\WINNT; C:\WINNT\System32\Wbem

PATHEXT=.COM;. E XE;. B AT;. C MD;. V BS;. V BE;. J S;. J SE;. W SF;. WSH

PROCESSOR_ARCHITECTURE=x86

PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 1, GenuineIntel

PROCESSOR_LEVEL=6

PROCESSOR_REVISION=0801

ProgramFiles=C:\Program Files

PROMPT=$P$G