Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set a variable in CMD?

I have the following command to set my own IP in a variable :

    for /F %I in ('curl http://ipecho.net/plain') do set ip=%I

When I open cmd and write (or paste) the command manually, it’s working properly. The variable %ip% is set and the command

    echo %ip%

returns my IP adress.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However if I put this command in a cmd file and run the cmd file, I’m getting the error :

    //ipecho.net/plain') was unexpected.

enter image description here

Does anyone know what I’m doing wrong please ?

Thanks.
Cheers,

>Solution :

Like it says in the help (for /?)

To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.

So, replace each %I by %%I.

Annoying, but there it is.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading