JSI Tip 9692. How can a batch script determine if a variable or parameter is an integer?

Jerold Schulman

August 30, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


An integer is a whole number, like 0, or 9, or 1234.

The basic syntax used to determine if a variable or parameter is an integer is:

if VariableOrParameter EQU +VariableOrParameter CommandToExecuteIfInteger

Samples:

if %1 EQU +%1 @echo %1 is an integer.if %1 NEQ +%1 goto errorif %var% EQU +%var% @echo Variable var contains an integer.For /f "Tokens=*" %%a in ('type %1') do ( if %%a NEQ +%%a @echo Line containing {%%a} in file %1 is NOT an integer.)



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like