【发布时间】:2019-05-09 18:38:05
【问题描述】:
很难用谷歌搜索这个,我有这个:
echo "age" | while read line; do
echo "$line"
done
但是有这种风格:
while read line; do
echo "$line"
done < echo "age"
首先,第二种样式不太对,但是第一种和第二种样式有名称吗?有任何功能/行为差异吗?
【问题讨论】:
-
第一个是流水线,第二个是重定向
-
< echo "age"将尝试从名为echo的文件中读取输入。<是文件重定向。你想要的是< <(echo "age")或<<< "age"" -
<(echo "age")是进程替换,<<< "age"是here-string。 -
但你可能想要heredoc:
while read line; do ...; done << EOF