Dummy command in windows cmd

前端 未结 4 1468
粉色の甜心
粉色の甜心 2021-01-17 10:49

In linux we have a makefile:

$(foreach A,a b,echo $(A) &&) true

It works and echos

a
b

Now we wan

4条回答
  •  有刺的猬
    2021-01-17 11:17

    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 in command.com times it used to be a command, so it worked even with input/output redirection. Today (in cmd.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 the echo command.

    cd. is the counterpart of true in Linux. Frame challenging the OP, it actually does something specific: it sets ERRORLEVEL to 0. It works with redirection.

    call is the counterpart of false 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.)

提交回复
热议问题