Zenedus
Zenedus

Reputation: 96

Trying to echo ^^ in batch

I am making batch animations, and to make nostrils I want to echo 2 carets, or ^^, but only one is displayed.

How do I stop/bypass the escape property of the caret character?

Upvotes: 0

Views: 108

Answers (4)

Bryce McDonald
Bryce McDonald

Reputation: 1870

Well technically, the caret ^ character is the escape character.

If you're wanting to display 2 carets, you can simply "escape the escape character".

The correct string to display 2 carets is below:

echo ^^^^

Upvotes: 5

Squashman
Squashman

Reputation: 14290

A couple of other ways to do this.

Use the FOR command.

for %%G IN ("^^") do echo %%~G

Use SET /P with NUL redirection. This one has some caveats. You can't put any spaces before the carets. If you need spaces before the carets there is another hack you can use with the backspace character.

<nul set /p ".=^^" &echo(

Upvotes: 3

aschipfl
aschipfl

Reputation: 34909

As an alternative to escaping the escape character (^^), you could use delayed expansion:

rem // Assign variable with `^` protected by `""`:
set "STR=^^"
rem // Use delayed expansion which happens after escaping:
setlocal EnableDelayedExpansion
echo !STR!

Upvotes: 4

UnhandledExcepSean
UnhandledExcepSean

Reputation: 12804

You could double them up and get the result you are looking for.

echo ^^^^

Upvotes: 3

Related Questions