Cruz Jean
Cruz Jean

Reputation: 59

Mysterious Echo Rules in Batch

I'm making a batch program that is supposed to be like a simplified(-ish) command prompt for commands that I make. I am wondering, though, about this line of batch coding that I have narrowed down as a fatal error (causes the cmd.exe running the program to close) causing line: echo One(1) application is within this folder. When I attempt to go to that section via inputting the command to run that section it states: application was unexpected at this time followed by immediately closing. I have also tried replacing "application" with "program", to no avail. I was wondering: What are all of the mysterious echo parameters/rules. for instance echo text >> name.extention is possible, but typing echo /? does not give you anything besides @echo on/off and echo text.

I believe it is something to do with the (), as in other languages it is used to call a function with the arguments within the (), but I do not understand why it would be this, as it is not running the "One" function because it is inside an echo, meant only to display it literally. Also, I don't believe batch has functions that can be called like this (I've only seen them in VB, lua, java, and C++ [of the ones I use])

If anyone knows why the program failed at this line, and/or (preferably and) all of the other hidden echo rules, please list them out for us; they really need to be known (I've seen so many questions on this website [and others] specifically about the echo command).

Upvotes: 1

Views: 109

Answers (1)

Magoo
Magoo

Reputation: 80033

Within a block statement where you have if expression (whatever1) else (whetever2) then you need to escape a closing parentheseis ) with a caret ^ thusly : ^)

The escape tells batch that the ) is NOT the termination of the then/else

Upvotes: 3

Related Questions