本文介绍了Bash foreach 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个输入(比方说一个文件).每行都有一个文件名.如何读取此文件并显示每个文件的内容.
I have an input (let's say a file).On each line there is a file name.How can I read this file and display the content for each one.
推荐答案
类似这样的事情:
xargs cat <filenames.txt
xargs
程序读取其标准输入,并且对于每一行输入运行 cat
程序,将输入行作为参数.
The xargs
program reads its standard input, and for each line of input runs the cat
program with the input lines as argument(s).
如果您真的想循环执行此操作,您可以:
If you really want to do this in a loop, you can:
for fn in `cat filenames.txt`; do
echo "the next file is $fn"
cat $fn
done
这篇关于Bash foreach 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!