Iterate over a list of files with spaces

前端 未结 11 1641
-上瘾入骨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 06:00

    Another solution for job...

    Goal was :

    • select/filter filenames recursively in directories
    • handle each names (whatever space in path...)
    #!/bin/bash  -e
    ## @Trick in order handle File with space in their path...
    OLD_IFS=${IFS}
    IFS=$'\n'
    files=($(find ${INPUT_DIR} -type f -name "*.md"))
    for filename in ${files[*]}
    do
          # do your stuff
          #  ....
    done
    IFS=${OLD_IFS}
    
    
    

提交回复
热议问题