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

后端 未结 4 724
庸人自扰
庸人自扰 2021-01-04 03:22

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-z

相关标签:
4条回答
  • 2021-01-04 03:38

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

    0 讨论(0)
  • 2021-01-04 03:44
    cd .
    

    also sets %ERRORLEVEL% to 0 but runs a bit faster and writes a bit shorter than ver>nul. Example:

    mkdir . 2>nul || cd .
    
    0 讨论(0)
  • 2021-01-04 03:49

    The context is a Windows cmd shell (used by the git-cmd.bat script):

    Following "Exiting batch with EXIT /B X where X>=1 acts as if command completed successfully when using && or || operators between batch calls", you could define in your path a true.bat file with:

    @%COMSPEC% /C exit 1 >nul
    
    0 讨论(0)
  • 2021-01-04 03:52
    VER>NUL
    

    works for me.

    For example,

    MKDIR . || VER>NUL
    

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

    0 讨论(0)
提交回复
热议问题