Can anyone explain to me why the -c
option exists in flock
?
I can't find a good description of how it differs from simply specifying the command(s) to execute after flock
(apart from its limitation of no arguments to the command).
Can anyone explain to me why the -c
option exists in flock
?
I can't find a good description of how it differs from simply specifying the command(s) to execute after flock
(apart from its limitation of no arguments to the command).
Copyright © 2021 Jogjafile Inc.
-c
invokes a shell with the command.Consider this:
Since
>
is interpretted by the current shell and not flock,myfile
will be truncated before the lock is captured.You can work around this with
-c
:Now the redirection is performed after the lock is captured. However, it is indeed useless since you could just have invoked a shell yourself: