Iterate over a list of files with spaces

前端 未结 11 1673
-上瘾入骨i
-上瘾入骨i 2020-11-22 05:16

I want to iterate over a list of files. This list is the result of a find command, so I came up with:

getlist() {
  for f in $(find . -iname \"f         


        
11条回答
  •  庸人自扰
    2020-11-22 05:53

    Since you aren't doing any other type of filtering with find, you can use the following as of bash 4.0:

    shopt -s globstar
    getlist() {
        for f in **/foo*
        do
            echo "File found: $f"
            # do something useful
        done
    }
    

    The **/ will match zero or more directories, so the full pattern will match foo* in the current directory or any subdirectories.

提交回复
热议问题