巴什foreach循环 [英] Bash foreach loop

查看:86
本文介绍了巴什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 程序读取它的标准输入,并为每个输入线与输入运行程序线作为参数(S)。

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

这篇关于巴什foreach循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆