Walrus
Walrus

Reputation: 389

How to use variable for file descriptor with flock?

I would like to do like this

( flock --nonblock ${descr} || exit

... 

) ${descr}>/tmp/smth.lock

but I got errors:

syntax error near unexpected token `${descr}'
`) ${descr}>/tmp/smth.lock'

So is it possible to use variable for descriptor? Could anybody help? Thank you!

Upvotes: 2

Views: 777

Answers (1)

chepner
chepner

Reputation: 531848

The syntax is {descr}>/tmp/smth.lock (no dollar sign) to allocate the file descriptor and assign it to the variable descr. After this, you could use descr as a normal variable.

Upvotes: 3

Related Questions