How to loop through file names returned by find?

前端 未结 13 1108
野性不改
野性不改 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:29

    based on other answers and comment of @phk, using fd #3:
    (which still allows to use stdin inside the loop)

    while IFS= read -r f <&3; do
        echo "$f"
    
    done 3< <(find . -iname "*filename*")
    

提交回复
热议问题