Skip
Skip

Reputation: 6521

Using variable in Batch FOR loop

I have the following statement in windows batch.

set machinename=%1
@FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd default') DO @%i

How to replace default by my variable "machinename" ?

Upvotes: 0

Views: 59

Answers (1)

user6250760
user6250760

Reputation:

How about this:

FOR /f "tokens=*" %%i IN ('docker-machine env --shell cmd "%~1"') DO %%~i

There is no need to have the machineName variable, as machineName points to %1. The ~ denotes to remove surrounding quotes, and add back extra quotes, just as a precaution.

Also, %i should be changed to %%i. %i is for command-line, and %%i is for a batch file.

Upvotes: 1

Related Questions