Pipeline in Windows batch backquote

2019-07-11 05:00发布

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.

1条回答
\"骚年 ilove
2楼-- · 2019-07-11 05:57

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
查看更多
登录 后发表回答