For variables, we use the set command to declare and assign variables
Declaring, Assigning and Accessing Variables
In batch scripting, upon declaring a variable, we must initialize it immediately
To declare variables, we follow the syntax:
set varName=valueTo access the value of the variable, we can enclose the variable name with %%.
Therefore, to output the value of the variable varName, we do the command:
echo %varName%We can also assign strings with spaces into variables.
To do this, we use double quotes to group together strings.
set greet="Hello World!"By default, variables only handle and store strings.
Therefore, numbers here are handled like strings
set userAge=19Input Prompts
We can also request the user for input then store it inside a variable using the set /p command.
We can create an input prompt using the following syntax:
set /p varName=<promptMessage>The prompt message is the string to be displayed when you request for input.
For example, consider the following script.
set /p age="How old are you?"
echo You are %age% years old!Special Variables
You can also use some special predefined variables that the system already defines for you