我试图避免创建任何新文件来存储输出,以尽量减少覆盖同名目录中某些内容的风险。我试图用管道评估流中的每一行,而不是输出到文件,然后使用 while read line do done < file
环形。像这样的东西:
echo -e "1\n2\n3\n4\n5" | #evaluate current line separately#
我能否以某种方式将每一行读入一个数组,然后计算数组中的元素?还是有更好的方法来避免意外覆盖文件?
最佳答案
在bash
中,常用的方法是使用Process Substitution:
while read line ; do
...
done < <( commands producing the input)
关于bash - 如何逐行评估流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11792508/