Reputation: 181
I'm quite new to bash scripting and i was having a look at permissions and i was wondering if there was a way to use a while loop to make it so that whilst the user is opening say
"file.txt" it becomes read only to everyone else until that file has been closed by the user again.
Is this possible in linux?
Upvotes: 2
Views: 1340
Reputation: 1
You might want file locking. See this page, the lockfile(1) man page, this question (which is very similar).
But I am not sure that you are right to reason at the shell script level. I'll do it inside the application, probably with lockf(3) or flock(2). You should avoid mandatory locking.
Be aware that editors might do their own file locking, or do other things than just writing files.
Some editors or programs might write a temporary file, then rename(2) it
Upvotes: 1