Output redirection to block-defined filehandle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The flock binary in modern linuxes (from util-linux-ng) supports
flocking a filehandle that is handled by the shell. Combining this
with per-code-block filehandles / io redirection, it is an incredibly
useful construct to protect a code block with a lock.

The resulting code looks like this (from man flock on Fedora 11):

      (
         flock -s 200
         # ... commands executed under lock ...
       ) 200>/var/lock/mylockfile

I am now discovering that this works in bash, but not in dash.

Is there a posixly correct way to do this? Can dash handle it? Is
there a syntax for this that is both dash and bash friendly?

If the answer is not -- this codepath is conditional. Is there a way
for me to test for which shell is running (and only attempt it under
bash)?

thanks!


martin
-- 
 martin.langhoff@xxxxxxxxx
 martin@xxxxxxxxxx -- School Server Architect
 - ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 - http://wiki.laptop.org/go/User:Martinlanghoff
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux