'how to escape a string correctly in a .bat file, so it can be output "as is" and not executed. Example, echo alfa < bravo

How can I make a .bat file print this to the console window without executing anything, I get all sorts of errors. Expected output:

Syntax: cmd.cmd -p <path> -c <command>
commands: mv
path: ./dirname <- no trailing slash

So .bat file having this code is not working:

@echo off
rem This doesnt work, will give error
echo Syntax: cmd.cmd -p <path> -c <command>
echo commands: mv
echo ./dirname <- no trailing slash
 
rem This works, but leaves quotes around sentence
echo "Syntax: cmd.cmd -p <path> -c <command>"
echo "commands: mv"
echo "./dirname ^<- no trailing slash"

Question was how did I output to console without getting errors or quotes. Looking at response I have since understood it was not quite clear what I asked of so hopefully this is clearer now.

UPDATED, THE SOLLUTION:

For my .bat to work I need to prefix all < and > signs with a ^. Doing so treats the < > as a printable character removing any possible other meaning or function. So answering my question:

@echo off
rem Note all < and > are prefixed with a ^
echo Syntax: cmd.cmd -p ^<path^> -c ^<command^>
echo commands: mv
echo path: ./dirname ^<- no trailing slash

I'm guessing ^ is a windows equivilant of PHP's \ (backslash), so it boils down to a escape sequence.



Solution 1:[1]

I need to escape the < and > characters with a ^, so a correct .bat file would look like this:

@echo off
rem Note all < and > are prefixed with a ^
echo Syntax: cmd.cmd -p ^<path^> -c ^<command^>
echo commands: mv
echo path: ./dirname ^<- no trailing slash

Updated main question aswell so hopefully this question will never lead to any confusion for anyone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1