How to cat multiple files from a list of files in Bash?

后端 未结 6 784
故里飘歌
故里飘歌 2020-12-16 18:08

I have a text file that holds a list of files. I want to cat their contents together. What is the best way to do this? I was doing something like this but it

6条回答
  •  隐瞒了意图╮
    2020-12-16 18:48

    #!/bin/bash
    
    files=()
    while read; do
        case "$REPLY" in
            \#*|'') continue;;
            *) files+=( "$REPLY" );;
        esac
    done < input
    cat "${files[@]}"
    

    What's better about this approach is that:

    1. The only external command, cat, only gets executed once.
    2. It's pretty careful to maintain significant whitespace for any given line/filename.

提交回复
热议问题