I have a variable in my batch file and it contains the pipe symbol (this one: |) so when I echo the variable I get an error about a unrecognized internal/external command.
I need a way to either get it to echo it correctly or better yet remove everything after and including the | symbol as well as any extra spaces before it.
In computing, echo is a command that outputs the strings that are passed to it as arguments. It is a command available in various operating system shells and typically used in shell scripts and batch files to output status text to the screen or a computer file, or as a source part of a pipeline.
To prevent echoing a particular command in a batch file, insert an @ sign in front of the command. To prevent echoing all commands in a batch file, include the echo off command at the beginning of the file.
When writing Batch files ( . bat ), ECHO. is used to print a blank line to the screen.
To create a blank line in a batch file, add an open bracket or period immediately after the echo command with no space, as shown below. Adding @echo off at the beginning of the batch file turns off the echo and does not show each of the commands. @echo off echo There will be a blank line below. echo.
There are several special characters that generally must be escaped when used in Windows batch files. Here is a partial list: < > & | ^ %
The escape character is ^
. So to get a literal |
, you should do this:
echo ^|
When the special character is in a variable, it becomes a bit harder. But if you use special syntax, you can replace characters in a variable like this:
set X=A^|B REM replace pipe character with underscore set Y=%X:|=_% echo %Y% REM prints "A_B"
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