Saturday, November 9, 2013

Batch Script: Checking empty variable

Share at Facebook

There is a tricky way to check whether a variable is empty or not in Batch script. Just have a look at the below example:

if x%TEST% == x echo empty string

In this example, the variable TEST is added with a value x and checking whether the concatenation of x and TEST is still x or not. If its still x which means TEST didn't have any value in it. Otherwise it had a value.

Simple, isn't it?

No comments: