Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does symbol ^ mean in Batch script?

In this command:

FOR /F %%A IN ('TYPE "%InFile%"^|find /v /c ""')DO SET "Till=%%A" 

what does the ^ mean?

like image 953
user3059908 Avatar asked Dec 03 '13 04:12

user3059908


People also ask

What is symbol in batch script?

The @ symbol tells the command processor to be less verbose; to only show the output of the command without showing it being executed or any prompts associated with the execution. When used it is prepended to the beginning of the command, it is not necessary to leave a space between the "@" and the command.

What does %% mean in batch file?

Represents a replaceable parameter. Use a single percent sign ( % ) to carry out the for command at the command prompt. Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> )

What does %1 mean in batch file?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.

What does ampersand mean in batch file?

The ampersand lets you construct, on one command line, compound-command statements that can run multiple commands.


2 Answers

The ^ symbol (also called caret or circumflex) is an escape character in Batch script. When it is used, the next character is interpreted as an ordinary character.

In your script, the output of the TYPE command to be written as the input to the FIND command.
If you don't use the escape character ^ before the |, then the regular meaning of | is a pipe character.

The Documentation says:

To display a pipe (|) or redirection character (< or >) when you are using echo, use a caret character immediately before the pipe or redirection character (for example, ^>, ^<, or ^| ). If you need to use the caret character (^), type two (^^).

like image 80
Infinite Recursion Avatar answered Sep 20 '22 06:09

Infinite Recursion


The caret '^' character serves two purposes in Windows batch files:

1. line continuations:

~~~

@echo off  dir ^ /ad ^ c:\temp 

~~~~

results in dir /ad c:\temp, which lists only the directories in C:\temp.

2. Escaping reserved shell characters & | ( < > ^.

Use a preceding caret to escape and print the character:

echo this pipe will print ^| but this one won't | echo and this will print one caret ^^ 
like image 41
Sunny Avatar answered Sep 22 '22 06:09

Sunny