Tuesday, December 16, 2008

Using caret '^' in Windows batch files

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

1. line continuations:
@echo off

dir ^
/ad ^
results in dir /ad c:\temp, which lists only the directories in C:\temp. (Thanks to SteveGTR for that example.)

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 ^^

1 comment:

Note: Only a member of this blog may post a comment.