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

前端 未结 5 731
闹比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:06

    I think starpause has the cleanest solution, however it fails when there is whitespaces in paths. This is fixed by setting IFS. The correct answer is therefore:

    IFS=$'\n'
    for i in $(find . -name '*.mov' ); 
    do
        echo "$i"
    done
    unset IFS
    

    You unset IFS in order to reset behaviour for IFS and as to why the $ is needed in IFS=$'\n', see https://unix.stackexchange.com/questions/184863/what-is-the-meaning-of-ifs-n-in-bash-scripting

提交回复
热议问题