How can I read a list of filenames from a file in bash?

前端 未结 7 1210
青春惊慌失措
青春惊慌失措 2021-01-30 10:59

I\'m trying to write a bash script that will process a list of files whose names are stored one per line in an input file, something the likes of

find . -type f          


        
7条回答
  •  天涯浪人
    2021-01-30 11:28

    Use read:

    while read F  ; do
            echo $F
    done 

    Alternatively use IFS to change how the shell separates your list:

    OLDIFS=$IFS
    IFS="
    "
    for F in $(cat /tmp/filelist.txt) ; do
      echo $F
    done
    IFS=$OLDIFS
    

    Alternatively (as suggested by @tangens), convert the body of your loop into a separate script, then use find's -exec option to run if for each file found directly.

提交回复
热议问题