[英]Batch file - Escape number
I need to echo url with get-parameters to a text file.我需要将带有 get-parameters 的 url 回显到文本文件。
When I am trying:当我尝试:
set url=text=2
echo %url% > file.txt
the result is almost ok:结果几乎没问题:
text=2
But there is one space after number 2 which is not needed但是数字 2 后面有一个空格是不需要的
If I try to remove that space from code:如果我尝试从代码中删除该空间:
set url=text=2
echo %url%> file.txt
but the result is just empty!但结果只是空的!
Is it possible to echo "text=2" without space at the end?是否可以在末尾没有空格的情况下回显“text=2”?
PS url in real code is actually like this:实际代码中的PS url其实是这样的:
set url=%~1
Two solutions两种解决方案
(echo %url%) >file
>file echo %url%
Your problem is the single number before the redirection is treated as stream number.您的问题是重定向之前的单个数字被视为流编号。
It's parsed as echo text= 2> file
, it tries to redirect only the stream2/stderr to the file now它被解析为echo text= 2> file
,它现在尝试仅将 stream2/stderr 重定向到文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.