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?

artyom.stv
  • 2,097
  • 1
  • 24
  • 42

5 Answers5

28

The rem command does nothing.

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • 3
    I wouldn't call it a command, but it definitely does nothing. – Lance Roberts Aug 26 '11 at 01:41
  • You are right, `rem` at the and of the line will take no effect. Thanks! – artyom.stv Aug 26 '11 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 Mar 03 '14 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 Mar 03 '14 at 15:53
  • `CALL REM` will set the ERRORLEVEL to `0` also. – it3xl Nov 22 '17 at 10:22
  • +stu, echo doesn't always output something. Try: `echo(` `echo[` `echo]` `echo.` `echo;` `echo:` `echo/` `echo\ ` `echo""""""""`. None of those will output anything if used on their own line. (Yes, not even "ECHO is ON" or anything) – Brent Rittenhouse Nov 02 '18 at 20:38
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!
Ricardo Stuven
  • 4,704
  • 2
  • 34
  • 36
  • Call used to call something up. What are you asking for? – NoNo Jul 24 '14 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?_" – Ricardo Stuven Jul 30 '14 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!) – AbstractDissonance Dec 28 '15 at 00:18
  • 5
    an empty call also seems to set the errorlevel to 1. Some might consider that a feature. – Paul Houle Oct 19 '17 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 Jan 03 '18 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.

zainka
  • 371
  • 2
  • 6
  • @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 May 22 '18 at 14:08
  • 3
    @jpaugh Not all commands. `break` or `echo` doesn't change the errorlevel. More infos at [dbenham about errorlevel](https://stackoverflow.com/a/34937706/463115) – jeb May 22 '18 at 14:29
  • 1
    this is a cross-platform solution. Nice! – lav Aug 14 '18 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.)

Jirka Hanika
  • 13,301
  • 3
  • 46
  • 75
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).

Vopel
  • 662
  • 6
  • 11