How to do it...

 Let's start our activity as follows:

  1. Open a terminal and create the recursive_read_input.sh script:
#!/bin/bashfunction recursive_func() {    echo -n "Press anything to continue loop "    read input    recursive_func}recursive_funcexit 0
  1. Execute the $ bash recursive_read_input.sh scriptpress Enter at the prompt and wait for another prompt.
  2. Exit the program with Ctrl + C.
  3. Open a terminal and create the loop_for_input.sh script:
#!/bin/bashfor (( ; ; ))
do
   echo "Shall run for ever"
   sleep 1
doneexit 0
  1. Execute the $ bash loop_for_input.sh scriptpress Enter at the prompt and wait for another prompt.

 

  1. Exit the program with Ctrl + C.
  2. Open a terminal and create the loop_while_input.sh script:
#!/bin/bashEXIT_PLEASE=0while : # Notice ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.