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:
#!/bin/bash
dobackup()
{
echo "Started backup"
tar -zcvf /dev/st0 /home >/dev/null 2>&1
echo "Completed backup"
}
dobackup &
echo -n "Task...done."
echoTest the script as follows:
$ chmod +x function_17.sh $ ./function_17.sh
Output:
Task...done. Started backup Completed backup
Command source and period (.)
Normally, whenever we enter a command, the new process gets created. If we want to make functions from the script to be made available in the current shell, then we need a technique that will run the script in the current shell instead of creating a new shell environment. The solution to this problem...