管道Windows批处理反引号 [英] Pipeline in Windows batch backquote
问题描述
我想看看我如何使用,还是难逃在Windows批反引号的管道,就像在Unix中炮弹。假设我有这样的:
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%
这会给我在今天的变量的日期。但我想有这样的1个或多个管道的工作:
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的抱怨宁可这样,我想我需要一个逃生机制?</ P>
cmd.exe complains err like this I think I need an escape mechanism?
| was unexpected at this time.
所以,这是可行的?怎么样?请注意,我有充分的GNU的coreutils和PATH大多数的好东西,所以我可以使用剪切就像例子。
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.
推荐答案
转义字符 ^
。
下面是命令,用设置
按替换回声
末做起来很友好。
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
这篇关于管道Windows批处理反引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!