Bash foreach loop

前端 未结 7 1219
别跟我提以往
别跟我提以往 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:26

    "foreach" is not the name for bash. It is simply "for". You can do things in one line only like:

    for fn in `cat filenames.txt`; do cat "$fn"; done
    

    Reference: http://www.cyberciti.biz/faq/linux-unix-bash-for-loop-one-line-command/

提交回复
热议问题