flock: how to run several commands?

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

-c, --command command
Pass a single command to the shell with -c.

With a single command, we have:

flock --exclusive --timeout 5 mylockfile.txt --command myscript.sh

But how to pass several commands?

Invoke the default shell (sh) or a specific shell (e.g. bash) explicitly:

flock --exclusive --timeout 5 mylockfile.txt --command sh -c 'myscript1.sh; myscript2.sh; myscript3.sh'

Variables changed within the command are local to the shell instance.