Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax of echo incorrect in Batch file

No idea whats going on here, so I hope someone can help.

I have a batch file that echos this:

echo +--------------------------------------------------------------------------+
echo | Booking System                                                           |
echo | By IT Department                                                         |
echo +--------------------------------------------------------------------------+
echo | IF YOU CAN SEE THIS, SOMETHING BROKE!                                    |
echo +--------------------------------------------------------------------------+
echo | IF YOU CAN NOT SEE THE BOOKING INTERFACE,PLEASE USE THE PHONE AND DIAL 0 |
echo +--------------------------------------------------------------------------+
echo |                                                                          |
echo +--------------------------------------------------------------------------+

But when I run the script, is gives me a Syntax error:

+--------------------------------------------------------------------------+
The syntax of the command is incorrect
like image 985
Michael Davison Avatar asked Jan 17 '26 10:01

Michael Davison


1 Answers

The problem lies with:

echo | Booking System |

The | is the pipe character which takes the output of the echo and tries to connect it to the standard input of a program called Booking (which probably doesn't exist) using the argument System, and then taking the output of that program and piping through to, well, nothing.

Hence the error, a syntax error caused by the final pipe with no program to run.

You should escape the pipe characters thusly:

echo ^| these will be treated as literal bar characters ^|

See the following transcript which shows a coup[le of errors caused by unescaped pipes (including the second one which matches your case) and the fix:

C:\users\Pax\Documents> echo | hello there
'hello' is not recognized as an internal or external command,
operable program or batch file.

C:\users\Pax\Documents> echo | hello there |
The syntax of the command is incorrect.

C:\users\Pax\Documents> echo ^| hello there ^|
| hello there |
like image 56
paxdiablo Avatar answered Jan 20 '26 02:01

paxdiablo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!