Running functions in the background

We have already seen in previous chapters that to run any command in the background, we have to terminate the command using &:

    $ command &

Similarly, we can make the function run in the background by appending & after the function call. This will make the function run in the background so that the Terminal will be free:

    echo "Started backup" 
    tar -zcvf /dev/st0 /home >/dev/null 2>& 1 
    echo "Completed backup" 
dobackup & 
echo -n "Task...done." 

Test the script as follows:

    $ chmod +x
    $ ./

This should produce the following output:

    Started backup
    Completed backup

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.