Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

bash

shell

cmd

I have written a Vim plugin which shells out to run external commands. Two of the commands I run are diff and grep which can each exit with a non-zero exit code during "normal" operation.

(diff exits with exit code 1 when it finds differences and grep 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

And:

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?

like image 482
Andy Stewart Avatar asked Feb 26 '14 16:02

Andy Stewart


People also ask

What is Windows equivalent of shell script?

Take a look at PowerShell, which is the closest you will get to a true scripting language like you have in Unix. Other than that, for simple things such as simply runnning an application, take a look at Windows command script/MS-DOS batch files.

What command shell does Windows use?

What is the Windows Command Prompt? Windows Command Prompt (also known as the command line, cmd.exe or simply cmd) is a command shell based on the MS-DOS operating system from the 1980s that enables a user to interact directly with the operating system.

What is the equivalent of source command in Windows?

The winget tool source command allows you to manage sources for Windows Package Manager. With the source command, you can add, list, update, remove, reset, or export repositories.

Is shell like CMD?

The command-line shell, sometimes called the command prompt or the terminal, is a tool that lets you control your computer using only textual commands. It offers a lot of power and simplicity (simplicity is different from ease of use).


1 Answers

VER>NUL

works for me.

For example,

MKDIR . || VER>NUL

issues an error message, but it sets %ERRORLEVEL% to 0.

like image 161
user368683 Avatar answered Oct 13 '22 01:10

user368683