24

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?

4
  • Depending on how make is running shell commands, "exit" might work nicely. Commented Aug 26, 2011 at 5:14
  • make will terminate execution after exit command.
    – artyom.stv
    Commented Aug 26, 2011 at 11:25
  • Odd. It must be parsing the commands itself, or more likely passing them as input to a persistent copy of cmd.exe. Thanks for letting me know. Commented Aug 27, 2011 at 0:47
  • break might fit your description (see break /?). On the other hand, your code examples have nothing to do with cmd or batch, so it might not in whatever language that is.
    – Stephan
    Commented Jul 9, 2020 at 19:35

5 Answers 5

29

The rem command does nothing.

6
  • 3
    I wouldn't call it a command, but it definitely does nothing. Commented Aug 26, 2011 at 1:41
  • You are right, rem at the and of the line will take no effect. Thanks!
    – artyom.stv
    Commented Aug 26, 2011 at 11:31
  • 3
    (I got interrupted) rem ruins a subshell... IF ERRORLEVEL 1 ( rem ) ELSE (set PROD=1) will cause the line to not run at all. What would be a good command to put in place of rem? echo doesn't work because it always outputs something.
    – stu
    Commented Mar 3, 2014 at 15:52
  • in linux, they run in a subshell in windows they do not unless you specify () I believe. I'm not a windows guru though.
    – stu
    Commented Mar 3, 2014 at 15:53
  • CALL REM will set the ERRORLEVEL to 0 also.
    – it3xl
    Commented Nov 22, 2017 at 10:22
23

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!
5
  • Call used to call something up. What are you asking for?
    – NoNo
    Commented Jul 24, 2014 at 22:28
  • 1
    @NoNo I'm saying that call without arguments is a noop. This answers the original question "Is there any dummy command in Windows in box (that really does nothing)? Or any nice hack?" Commented Jul 30, 2014 at 20:51
  • This doesn't work for in some cases, I have a group that if I don't use echo then for some reason it falls through to the next group. I tried call but it still falls through. trying to find something that works like echo but doesn't print. (echo off works!) Commented Dec 28, 2015 at 0:18
  • 5
    an empty call also seems to set the errorlevel to 1. Some might consider that a feature.
    – Paul Houle
    Commented Oct 19, 2017 at 20:17
  • @PaulHoule thanks for pointing this out. If you want errorlevel set to 0 at the end of the command, a different solution is needed.
    – aaaantoine
    Commented Jan 3, 2018 at 16:27
21

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.

3
  • @jeb Won't any command set the error level, to indicate whether it was successful or not? true and false both do this on Linux.
    – jpaugh
    Commented May 22, 2018 at 14:08
  • 3
    @jpaugh Not all commands. break or echo doesn't change the errorlevel. More infos at dbenham about errorlevel
    – jeb
    Commented May 22, 2018 at 14:29
  • 1
    this is a cross-platform solution. Nice!
    – lav
    Commented Aug 14, 2018 at 12:37
5

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

4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.