繁体   English   中英

Bash 用 WSL 进行进程替换

[英]Bash Process Substitution with WSL

我试图了解我的设置中的以下(奇怪的?)行为。 我正在使用 WSL 运行 Windows 10。

这是我从我的 powershell+wsl session 看到的:

$ ./run.sh

Windows IP Configuration
<cut>
1

和:

$ cat run.sh
#!/bin/bash

mkdir -p dir/1
mkdir -p dir/2
mkdir -p dir/3

var=0
while read i;
do
  ((var++))
  ipconfig.exe
done < <(find dir -type d)

echo $var

如果我现在注释掉ipconfig.exe行:

...
  #ipconfig.exe
...

这是我现在得到的:

$ ./run.sh
4

为什么调用 window 可执行文件(例如ipconfig.exe )似乎会干扰我的while循环)?

以供参考:

$ uname -a
Linux FR-L0002146 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ bash -version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

ipconfig.exe很可能是从标准输入读取的,因此它正在吸收来自进程替换的输入。 将其输入重定向到/dev/null以防止这种情况。

while read i;
do
  ((var++))
  ipconfig.exe </dev/null
done < <(find dir -type d)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM