How to exit from find -exec if it fails on one of the files

后端 未结 5 612
花落未央
花落未央 2021-01-17 08:29

I want to run the command

find some/path -exec program \\{} \\; 

but I want the find command to quit as soon as the command



        
5条回答
  •  暖寄归人
    2021-01-17 09:05

    You could pipe the output from find to another subprocess and use while/break:

    find some/path | while read f
    do
        program $f
        if [ $? -ne 0 ]
        then
            break
        fi
    done
    

提交回复
热议问题