0

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" ?

4
  • Are you just looking for how to use variables in batch? Commented Oct 7, 2017 at 15:43
  • That code will never work in a batch file. Commented Oct 7, 2017 at 15:52
  • After you've fixed the code in response to @Squashman's comment, replace default with either %1 or %machinename% Commented Oct 7, 2017 at 16:39
  • Open a command prompt window and run for /?. This outputs the help for command FOR with first sentence in fourth paragraph: To use the FOR command in a batch program, specify %%variable instead of %variable. Next run call /? and it is explained in output help how arguments can be referenced in a batch file. Then run set /? and the output help explains the usage of environment variables. And if you need a list of commands, run in command prompt window help. Commented Oct 7, 2017 at 18:30

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.