I need to echo a string containing angle brackets (< and >) to a file on a Windows machine. Basically what I want to do is the following:echo some string < with angle > brackets >>myfile.txt
This doesn't work since the command interpreter gets confused with the angle brackets. I could quote the whole string like this:echo "some string < with angle > brackets" >>myfile.txt
But then I have double quotes in my file that I don't want.
Escaping the brackets ala unix doesn't work either:echo some string \< with angle \> brackets >>myfile.txt
Ideas?
If you need to use any of these characters as part of a command-line argument to be given to a program (for example, to have the find command search for the character >), you need to escape the character by placing a caret (^) symbol before it.
The angle brackets ( < > ) indicate that the enclosed element (parameter, value, or information) is mandatory. You are required to replace the text within the angle brackets with the appropriate information. Do not type the angle brackets themselves in the command line.
The square brackets ( [ ] ) indicate that the enclosed element (parameter, value, or information) is optional. You can choose one or more items or no items. Do not type the square brackets themselves in the command line.
Escape sequences allow you to send nongraphic control characters to a display device. For example, the ESC character (\033) is often used as the first character of a control command for a terminal or printer. Some escape sequences are device-specific.
The Windows escape character is ^, for some reason.
echo some string ^< with angle ^> brackets >>myfile.txt
True, the official escape character is ^
, but be careful because sometimes you need three ^
characters. This is just sometimes:
C:\WINDOWS> echo ^<html^> <html> C:\WINDOWS> echo ^<html^> | sort The syntax of the command is incorrect. C:\WINDOWS> echo ^^^<html^^^> | sort <html> C:\WINDOWS> echo ^^^<html^^^> ^<html^>
One trick out of this nonsense is to use a command other than echo
to do the output and quote with double quotes:
C:\WINDOWS> set/p _="<html>" <nul <html> C:\WINDOWS> set/p _="<html>" <nul | sort <html>
Note that this will not preserve leading spaces on the prompt text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With