Windows batch: echo without new line

后端 未结 18 1675
失恋的感觉
失恋的感觉 2020-11-22 04:01

What is the Windows batch equivalent of the Linux shell command echo -n which suppresses the newline at the end of the output?

The idea is to write on t

18条回答
  •  执笔经年
    2020-11-22 04:50

    Using: echo | set /p= or will both work to suppress the newline.

    However, this can be very dangerous when writing more advanced scripts when checking the ERRORLEVEL becomes important as setting set /p= without specifying a variable name will set the ERRORLEVEL to 1.

    A better approach would be to just use a dummy variable name like so:
    echo | set /p dummyName=Hello World

    This will produce exactly what you want without any sneaky stuff going on in the background as I had to find out the hard way, but this only works with the piped version; will still raise the ERRORLEVEL to 1.

提交回复
热议问题