echo off
setlocal enableDelayedExpansion
set /p "short_description=description:"
if not defined short_description set "short_description={short_description}"
set /p "entry_point=entry point: (index.js)"
if not defined entry_point set "entry_point=index.js"
`for %%I in (
"{"
" "description": "%short_description%","
" "main": "%entry_point%","
"}"
) do (
if %%I=="." (
echo.>> "package.json"
) else (
echo %%~I>> "package.json"
)
)
当提示变量文本中有空格时,输出最终在变量字符串的每个空格字符中都有换行符。
举个例子: 这是我的测试响应提示:
description:description with spaces in the text
entry point: (index.js)index.html
这是输出
{
"description": "description
with
spaces
in
the
text","
"main": "index.html",
}
它应该是这样的:
{
"description": "description with spaces in the text",
"main": "index.html",
}