This refers to something I recall happening some time ago, but would like to have some input for learning purposes.
In a Bash script, copying a large file to a USB flash drive, the copying process completes ...... but of course the write of the file to the drive is not completed, as the file is actually cached I understand, and will continue to be written to the drive long after the command completes.
This presented a problem, as the size of the file is unknown, as is the speed of the write to the drive, so no allowance could be made for the time it would take.
Now if that copy command was followed by another command which used that file (I think that was the case), the second command will kick in while the writing is still happening, as the copy command itself has completed.
I think that was the situation that presented itself.
IIRC, it was worked around by doing another small write to the drive immediately after the copy, which did not begin until the drive was free to be written to, and completed without needing cache.
Thus the real second command could be executed as the write of the file was definitely completed.
I hope I have remembered that correctly ...... and been able to explain it properly.
My question then is this ....... is there a 'proper' means of determining that a copy and write to such a drive has completed before the next command is executed?
Maybe something obvious that I just do not know about, or remember?