Question

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?

Was it helpful?

Solution

The rem command does nothing.

OTHER TIPS

The call command without any argument does nothing and has no collateral effect as rem has.

Example:

echo Wait for it...
call
echo Nothing happened!

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.

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top