title: Terminate shell script after three invalid input
body: <p>Restricting user from trying multiple invalid attempt in shell scripting. I wrote the below script but somehow it's not getting me desire output. I have shared the script and script output both. Kindly help. Here I wanted script to terminate if user tried more than 3 times.</p>
  <pre><code>While true
  do
  echo -n &quot;Enter yes or no&quot;
  read opt
  case $opt in
  yes) break ;;
  no) break ;;
  *) echo &quot;Invalid input&quot;
  while [[ $err -le 3 ]]
  do
   If [[ $err -le 3 ]]
  then
  echo &quot;err: $err&quot;
  ((err++))
  break
  else
  echo &quot;Max limit crossed&quot;
  exit 1
  fi
  done
  ;;
  esac
  done
  </code></pre>