echo is adding space when used with a pipe

前端 未结 2 1756
栀梦
栀梦 2020-12-20 15:06

While answering this question I found some strange behavior for which I have no explanation

for /f \"delims=\" %a in (\'(for /l %z in (1,1,10^) do @echo %z^)         


        
2条回答
  •  误落风尘
    2020-12-20 15:27

    Redirection operators apply to the command they are closest to--not the entire line.

    In your three test cases, you're redirecting the stdout of the echo and set commands to a file. By redirecting stdout, there is nothing left to pipe to more or sort.

    In your nested for loop example, I think there are some unneeded parentheses causing the headaches. Try this instead:

    for /f "delims=" %a in ('for /l %z in (1,1,10^) do @echo %z^|sort') do @echo %a0
    

提交回复
热议问题