Batch equivalent of Bash backticks

You can get a similar functionality using cmd.exe scripts with the for /f command:

for /f "usebackq tokens=*" %%a in (`echo Test`) do my_command %%a

Yeah, it’s kinda non-obvious (to say the least), but it’s what’s there.

See for /? for the gory details.

Sidenote: I thought that to use “echo” inside the backticks in a “for /f” command would need to be done using “cmd.exe /c echo Test” since echo is an internal command to cmd.exe, but it works in the more natural way. Windows batch scripts always surprise me somehow (but not usually in a good way).

Leave a Comment