Windows bat alternative for Bash inline command

2020-03-17 04:54发布

Is there any Windows equivalent syntax to run a command within another command in a bat script file?

In Linux, you can simply use $(...) or ``.

1条回答
对你真心纯属浪费
2楼-- · 2020-03-17 05:24

Yes, at least for simple things:

@setlocal enableextensions enabledelayedexpansion
@echo off
for /f %%w in ('echo xyzzy') do set var=%%w
echo Output is %var%
endlocal

The output of that script is:

Output is xyzzy

with the xyzzy coming from the echo command.

Running for /? from a command window should give you a more comprehensive list of options.

查看更多
登录 后发表回答