我正在嘗試在 set /p 變數提示符內插入新行,這是一個示例。
set /p variableName=[1] - this\n[2] - or this
output:
[1] - this
[2] - or this
uj5u.com熱心網友回復:
恐怕它不像你想的那樣作業。
我找到了這個,并創建了以下代碼,其中變數PText包含您想要的行,然后用作SET /P命令中的提示:
@ECHO OFF
SET PText=[1] - this^& ECHO;[2] - or this
SET /P variableName=%PText%
ECHO;Answer=[%variableName%]
當我運行代碼時,它會列印[1] - this,我回答ABC并按 enter,然后列印[2] - or this,然后列印以下ECHO命令Answer=[ABC]:
[1] - thisABC
[2] - or this
Answer=[ABC]
我相信唯一真正的答案是ECHO在做之前你想要什么SET /P,或者使用這個頁面CHOICE上描述的命令。
示例SET /P:
ECHO;[1] - this
ECHO;[2] - or this
SET /P variableName=[1,2]?
uj5u.com熱心網友回復:
就像SomethingDark建議的那樣,您可以簡單地使用echo線條
echo [1] This
set /p "var=[2] - or this "
但是如果你堅持只使用set /p它可以做到
@echo off
setlocal EnableDelayedExpansion
(set \n=^
%=empty=%
)
set /p "var=[1] This!\n![2] or this"
uj5u.com熱心網友回復:
要在文本中實際插入換行符:
@echo off
setlocal enabledelayedexpansion
set nl=^
::The Above empty lines are critical for this function, do not delete.
set /p "var=[1] - this!nl![2] - or this!nl!"
echo %var%
就我個人而言,我不確定您為什么不使用choice它?
echo [1] - This & echo [2] - or this & choice /c 12
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/470187.html
