Q:

Exit bash script within while loop

How do you exit a script from within a find piped while loop? 
E.g. following exit just exits the piped subshell:
find some_directory -type d|while read dir_name; do
  if [ -w "$dir_name" ]; then
    exit 1
  fi
done

A:

You can check the return status of the pipe:
if !  find some_directory -type d|while read dir_name; do
  if [ -w "$dir_name" ]; then
    exit 1
  fi
done; then exit 1; fi

Or, more simply:
 find some_directory -type d|while read dir_name; do
      [ -w "$dir_name" ] && exit 1
    done || exit 1

