title: Exit entire program from a function call in shell?
body: <p>I have a function which I use in my shell script and based on a certain condition I'd like to call "exit 0" in that function so that the entire script exits. But for some reason the program still runs after calling exit 0 in the function. Why?</p>
  
  <pre><code>check()
  {
      printf "Would you like to try again?\n"
      read S
      if [ "$S" = "y" ]
      then 
          ./myprog
      else    
          exit 0  
      fi
  }
  </code></pre>
  
  <p>And I call it like this:</p>
  
  <pre><code>if test $WRONG -eq 7
  then
      printf "Sorry\n"
      check
  fi
  </code></pre>