How to do it...

Let's start our activity as follows:

  1. Open a terminal and create the loop_and_print.sh script:
#!/bin/bash
EXIT_PLEASE=0INC=0until [ ${EXIT_PLEASE} != 0 ] # EXIT_PLEASE is set to 0, until will never be satisfieddo   echo "Boo $INC" > /dev/null   INC=$((INC + 1))   sleep 1doneexit 0
  1. Open a terminal and run the following commands:
$ bash loop_and_print.sh &$ ps aux | grep loop_and_print.sh # Take note of the PID - write it down
  1. Next, log off, then log in and run the following command in a new terminal:
$ ps aux | grep loop_and_print.sh # Take note of the PID - write it down
  1. Can you find the process running? Next, run the following command:
$ bash loop_and_print.sh & # note the PID againg$ disown
  1. Next, log off, then log in ...

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.