What does ^& represent in Windows command line?

14

2

I've noticed the usage of ^& in:

(robocopy c:\dirA c:\dirB *.*) ^& IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0

I am wondering what does it do?

Thrash Abaddon

Posted 2019-01-07T18:00:53.770

Reputation: 251

1

Also see Is typing %^ into cmd.exe a Windows easter egg?

– rahuldottech – 2019-01-08T09:10:40.013

Answers

18

The ^ symbol is the escape character* in Cmd.exe:

Adding the escape character before a command symbol allows it to be treated as ordinary text.
When piping or redirecting any of these characters you should prefix with the escape character: & \ < > ^ |

Source

However, it has no effect and is actually unnecessary in your command. It appears you want the IF command to be run after the RoboCopy command completes. Therefore you want the & to be parsed as the "command separator" command, which tells Cmd.exe to treat your IF statement as a second command that should be executed after running RoboCopy. As a result, this command is equivalent to the one you're using:

(robocopy c:\dirA c:\dirB *.*) & IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0 

*If ^ is the last character in a command, then it is interpreted as the command continuation character.

More Information:

I say Reinstate Monica

Posted 2019-01-07T18:00:53.770

Reputation: 21 477

1@Biswapriyo That's also true, to use ^ for that purpose it must be the last character in the command. – I say Reinstate Monica – 2019-01-07T18:23:10.803