关于shell中的while文本重定向问题
#!/bin/bash
cat vscode_tutor.txt | while read line
do
echo $line > hello.txt
done
那么重定向第一次过后,就会跳出while循环。只会把vscode_tutor.txt的第一行输出到hello.txt。
要想完整输出代码如下:
#!/bin/bash
cat vscode_tutor.txt | while read line
do
echo $line
done > hello.txt
此外,一些吸入stdin的shell指令也会影响while循环的运行。例如adb shell将stdin连接到设备上运行的命令,该命令通常会消耗stdin直到达到EOF。 因此,这些命令占用了设备的所有其余名称,从而导致循环退出。
要想不影响while循环,$(adb -s $device shell ...v</dev/null)使用<进行重定向。
参考链接

浙公网安备 33010602011771号