How can I process the results of find in a bash script?

前端 未结 5 732
闹比i
闹比i 2020-12-07 15:54

I\'m trying to use an array to store a list of file names using the find command.

For some reason the array fails to work in the bash used by the school

5条回答
  •  既然无缘
    2020-12-07 16:13

    You could use something like that:

    find . -name '*.txt' | while read line; do
        echo "Processing file '$line'"
    done
    

    E.g. make a copy:

    find . -name '*.txt' | while read line; do
        echo "Copying '$line' to /tmp"
        cp -- "$line" /tmp
    done
    

    HTH

提交回复
热议问题