How to loop through file names returned by find?

前端 未结 13 1131
野性不改
野性不改 2020-11-22 04:20
x=$(find . -name \"*.txt\")
echo $x

if I run the above piece of code in Bash shell, what I get is a string containing several file names separated

13条回答
  •  悲哀的现实
    2020-11-22 04:43

    # Doesn't handle whitespace
    for x in `find . -name "*.txt" -print`; do
      process_one $x
    done
    
    or
    
    # Handles whitespace and newlines
    find . -name "*.txt" -print0 | xargs -0 -n 1 process_one
    

提交回复
热议问题