As soon as you notice here , the problem is that you need to wait for the programs that you run from your script to finish working.
If in a script you run the program in the background , you can try something else.
In general, calling sync before exiting flushes the file system buffers and may help a bit.
If in a script you run some programs in the background ( & ), you can wait for them to finish before exiting the script. To have an idea of ββhow it can function, you can see below
#!/bin/bash
Since wait works with jobs as well as PID numbers, a lazy solution should be to end the script
for job in `jobs -p` do wait $job done
A more complicated situation is if you run something that starts something else in the background, because you have to look and wait (if so) for the end of the entire child process: for example, if you run daemon , you probably shouldn't wait completion :-).
Note:
wait $ {!} means "wait for the last background process to complete", where $! is the PID of the last background process. Therefore, to put wait ${!} Immediately after program_2 & , it is equivalent to directly executing program_2 without sending it in the background using &
Using wait :
Syntax wait [n ...] Key n A process ID or a job specification
Hastur Jun 26 '14 at 6:37 2014-06-26 06:37
source share