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

后端 未结 5 608
花落未央
花落未央 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

    % _find_trap() {
    >   _find_pid="${1}" ; _find_ops="${2}" ; _find_trigger="${3}"
    >   shift 3 && set -- "${@}" 
    >   trap 'kill -s INT "-${_find_pid}" \
    >     unset _find_pid _find_ops _find_trigger ; set - \
    >     1>&2 printf "%s" "find killed due to trap" \
    >     exit [CODE] ' TRAP
    >  while { sh -c "${_find_ops} ${@}"} {
    >    [ "${_find_trigger}" ] && { kill -s TRAP "-${_find_pid}" ; break ; }
    >    ...
    >  }
    > export -f _find_trap ; find . -execdir _find_trap \"$$\" \"${cmds}\" \
    >   \"${testable_trigger}\" "{}" +
    

提交回复
热议问题