Reputation: 911
I would like to see how I can use, or escape pipeline in a back quote in windows batch just like in Unix shells. Suppose I have this:
FOR /F "usebackq delims=" %i IN (`date /t`) DO @set TODAY=%i
echo %TODAY%
This will give me the date in TODAY variable. But I want to have this 1 or more pipeline working:
FOR /F "usebackq delims=" %i IN (`date /t | cut -c 1-3`) DO @set TODAY=%i
cmd.exe complains err like this I think I need an escape mechanism?
| was unexpected at this time.
So, is this doable? How? Please note that I have full gnu coreutils and most goodies in PATH so I can use cut just as example.
Upvotes: 3
Views: 1724
Reputation: 10181
The escape character is ^
.
Here is the command, with set
replaced by echo
at the end to make it SO friendly.
FOR /F "usebackq delims=" %i IN (`date /t ^| cut -c 1-3`) DO @echo TODAY=%i
TODAY=18/
(YMMV, I have a French locale for date)
date /t
18/02/2013
Upvotes: 6