Bash foreach loop

前端 未结 7 1252
别跟我提以往
别跟我提以往 2020-12-22 20:39

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.

7条回答
  •  既然无缘
    2020-12-22 21:16

    Something like this would do:

    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
    

提交回复
热议问题