Windows cmd 中的虚拟命令
在 Linux 中,我们有一个 makefile:
$(foreach A,a b,echo $(A) &&) true
它可以工作并回显
a
b
现在我们想将其移植到 Windows。我发现的 Windows 中最短的不执行任何操作的命令:
if 0==1 0
因此 makefile 示例将类似于
$(foreach A,a b,echo $(A) &&) if 0==1 0
Is there any dummy command in Windows in box (that确实不执行任何操作)?或者有什么好的技巧吗?
In linux we have a makefile:
$(foreach A,a b,echo $(A) &&) true
It works and echos
a
b
Now we want to port it to Windows. The shortest command I've found for Windows that does nothing:
if 0==1 0
So the makefile example will look like
$(foreach A,a b,echo $(A) &&) if 0==1 0
Is there any dummy command in Windows in box (that really does nothing)? Or any nice hack?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
rem 命令不执行任何操作。
The
rem
command does nothing.不带任何参数的
call
命令不执行任何操作,也没有rem
那样的附带效果。例子:
The
call
command without any argument does nothing and has no collateral effect asrem
has.Example:
老话题,新答案。
当我不想在 Windows 中执行任何操作(而且我经常这样做)时,我一直在使用 cd.,因为“将目录更改为自身”就其本身而言根本没有副作用我可以看到。
Old thread, new answer.
I have been using
cd.
when I want to do nothing in windows (and I often do) since "change directory to itself" has no side effects at all as far as I can see.对于哪个虚拟命令最短没有单一的答案,因为虚拟命令有几种不同的目的(上下文),可能会导致不同的选择。从最好到最差列出。
@
擅长于长度和无所事事。它在命令行末尾运行良好。rem
很棒,在command.com
时代它曾经是一个命令,所以即使在输入/输出重定向的情况下它也能工作。今天(在cmd.exe
中)它开始注释,因此它只能在命令行末尾使用;任何重定向最终也会被注释掉。echo.
甚至可以与输入/输出重定向一起使用。该点不会被打印,回显状态也不会改变。如果在命令批处理的开头使用,则可能需要将其拼写为@echo。
如果您不希望虚拟命令本身回显到标准输出;但这对于echo
命令来说并不特殊。cd.
与 Linux 中的true
相对应。框架挑战OP,它实际上做了一些特定的事情:它将ERRORLEVEL设置为0。它与重定向一起工作。call
与 Linux 中的false
相对应。该命令认为它应该被告知要调用什么,但如果您没有提及任何内容,它会让您在没有任何错误消息的情况下继续,但将 ERRORLEVEL 设置为正值。它与重定向一起使用。(此摘要借鉴了三个现有答案,以及另一个网站上另一个问题的此答案。尝试一种老式的方法规范的答案。)
There is no single answer as to which dummy command is shortest, because there are several different purposes (contexts) for the dummy command that may lead to different choices. Listing from best to worst.
@
excels in length and in doing nothing. It works well at the end of the command line.rem
is great, and incommand.com
times it used to be a command, so it worked even with input/output redirection. Today (incmd.exe
) it starts a comment, so it is only usable at the end of a command line; any redirection would end up commented out, too.echo.
works even with input/output redirection. That dot does not get printed, echo state is not altered. If used on the beginning of a command batch, you might need to spell it@echo.
if you do not want the dummy command itself to be echoed to the standard output; but that's not special to theecho
command.cd.
is the counterpart oftrue
in Linux. Frame challenging the OP, it actually does something specific: it sets ERRORLEVEL to 0. It works with redirection.call
is the counterpart offalse
in Linux. The command thinks it deserves to be told what to call, but if you didn't mention any, it lets you go without any error message, but setting ERRORLEVEL to a positive value. It works with redirection.(This summary draws on three existing answers, plus this answer to another question on another site. Attempting an old fashioned canonical answer.)
break 是任何想要在 Windows cmd 中使用无操作命令的人所寻找的。自 Windows 98 以来(甚至可能更早),它就没有做过任何事情。
break is what anyone who wants a no-op command in Windows cmd is looking for. It hasn't done anything since Windows 98 (or maybe even before that).