Andy Stewart Andy Stewart - 1 year ago 58
Bash Question

What's the Windows command shell equivalent of bash's `true` command?

I have written a vim plugin which shells out to run external commands. Two of the commands I run are

which can each exit with a non-zero exit code during "normal" operation.

exits with exit code 1 when it finds differences and
exits with exit code 1 when it doesn't find matches.)

For the purposes of my Vimscript I need to return an exit code of 0 from these commands. So far I'm constructing the commands like this:

diff a b || true


grep foo bar || true

This works for me on OS X and it apparently works for some Windows users. However when I run Windows 7 on OS X via Virtualbox, using the bash installed by the git installer, I get the error message:
'true' is not recognized as an internal or external command, operable program or batch file.

What is the correct successful-no-op command to use on Windows?

Answer Source

true is roughly equivalent to (exit 0) (the parentheses create a subshell that exits with status 0, instead of exiting your current shell.