8

If I end a line in cmd with ^, it will ask for more input.

D:\some\folders>do ^
More? stuff

Let's say I don't want to enter do every time I wanna do stuff so I put it in a .bat, and let's say the stuff I want to do varies each time. So I create the following .bat file:

do ^

and I run it and expect it to ask for More? so I can enter my stuff. But it doesn't. It does nothing for all eternity. How do I make it work?

2 Answers 2

12

The ^ character is the batch file "escape" character. When used by itself at the end of a line, it becomes a line-continuation character, used for treating multiple lines as a single line.

So, in a batch file, if you put in

echo This ^
is a single ^
line!

It treats it as a single line, equivalent to:

echo This is a single line!

If there is no "next line" in the batch, like in your single line batch example of do ^, there's no next line to append, so it doesn't append anything (and therefore appears to do nothing).

When you use the ^ line-continuation at a command prompt, it will show you the More? prompt because you told it you want to continue the command on the next line, at which point you can continue the command, e.g.:

Y:\>echo This ^
More? is a single ^
More? line!
This is a single line!

To have a batch file stop and prompt for input, you would want to look into using set /p, which will prompt for input and then assign that input to a variable. e.g.:

set /P name="What Is Your Name? "
echo Hello %name%!
0
12

If you want a batch to prompt you for input you're going to use set /p. For example to create a variable %stuff% you can use in the batch the command would look like this.

set /p stuff=What stuff do you want to do?:

This will put the prompt "What stuff do you want to do?" and you can enter the stuff, this will then be in the %stuff% variable you can use elsewhere in your script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .