Bharath
Bharath

Reputation: 665

how to assign an ip address to a variable in batch

I have assigned ip address to a variable in the following way.

  set /A myvar = 10.0.0.1
  echo %myvar%

but it is giving the result as only 10 not entire ip address.. so can some give the solution for it

Upvotes: 0

Views: 570

Answers (4)

Stas Berkov
Stas Berkov

Reputation: 81

try this:

set myvar=10.0.0.1 
echo %myvar% 

The /A switch specifies that the string to the right of the equal sign is a numerical expression that is evaluated. The expression evaluator Note: no spaces around "=" sign

Upvotes: 2

Anders Lindahl
Anders Lindahl

Reputation: 42910

Get rid of the /A, then it will work.

C:\>help set
[...]
The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated.
[...]

Upvotes: 1

YOU
YOU

Reputation: 123889

Just don't use /A, its for numerical expressions

set myvar=10.0.0.1
echo %myvar%
//10.0.0.1

Upvotes: 1

Senica Gonzalez
Senica Gonzalez

Reputation: 8192

Can you put quotation marks around the ip address? "10.0.0.1"

Upvotes: 0

Related Questions