I am reading this snippet for using flock
:
exec {lock_fd}>/var/lock/mylockfile || exit 1
flock -n "$lock_fd" || { echo "ERROR: flock() failed." >&2; exit 1; }
# ... commands executed under lock ...
flock -u "$lock_fd"
And I have no idea what does {lock_fd}
means there. I have tried to run this in my shell, and echo its value out repetitively:
~/learning-material/shell master*
❯ exec {lock_fd}>test.lock
~/learning-material/shell master*
❯ echo $lock_fd
18
~/learning-material/shell master*
❯ exec {lock_fd}>test.lock
~/learning-material/shell master*
❯ echo $lock_fd
19
What does that mean? What is the syntax related with {lock_fd}
? My guess right now is that is a file descriptor, or a unique ID that will be increased automatically.