bash命令在while循环中重定向标准输入(使用sed)

Jon*_*han 4 bash stdin while-loop readfile

我正在尝试仅从文件(output.txt)到while循环的1到1000行。

我已经尝试过这样的事情:

#!/bin/bash
while read -r line; do
    echo "$line"
done < (sed -n 1,1000p data/output.txt)
Run Code Online (Sandbox Code Playgroud)

Jon*_*han 5

刚刚尝试过:

#!/bin/bash
while read -r line; do
    echo "$line"
done < <(sed -n 1,1000p data/output.txt)
Run Code Online (Sandbox Code Playgroud)

添加另一个尖括号“ <”可以解决问题...如果有人可以解释这可能很有趣。

谢谢

  • 搜索 `bash` [进程替换](http://wiki.bash-hackers.org/syntax/expansion/proc_subst) 和 [输入重定向](http://wiki.bash-hackers.org/syntax/重定向#redirecting_input) (2认同)