How to Declare Variables in Batch Script
- Declare Variables in Batch Script
- Declare Variables With Numeric Values in Batch Script
- Declare Variables With String Values in Batch Script
This article will demonstrate how to declare and define variables in Batch Script.
Declare Variables in Batch Script
In Batch, there is no requirement to use any other keyword to declare an integer, float, double, or string type variable.
The general format for declaring variables in a Batch Script is shown below.
Syntax:
set VARIABLE_NAME=VALUE
Let’s see some examples regarding this topic.
Declare Variables With Numeric Values in Batch Script
The example below will demonstrate how to declare a variable and provide it with a numeric value. After that, print the variable value as output.
Example:
@echo off
set numeric_var=20
set numeric_var1=8.979
echo %numeric_var%
echo %numeric_var1%
Output:
20
8.979
Declare Variables With String Values in Batch Script
The below example will demonstrate how to declare a string variable. After that, display the variable value as output.
Example:
@echo off
set string_var=This is a string
echo %string_var%
Output:
This is a string
Remember, all methods discussed here are written using Batch Script and only work in Windows CMD.
Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.
LinkedIn