After looking into flock
I'm a bit confused. Basically there are two forms:
flock [options] <file|directory> <command> [command args]
flock [options] <file descriptor number>
Now if I want to use the second form I need to use exec 200<> file
. Then I lock the file with flock 200
.
Now I prevented my script from mutilating file
because it needs to acquire the lock before doing so. Still why did I have to create the descriptor first? I can operate on file
perfectly fine without using that descriptor.
So why am I forced to create a descriptor?