Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
no_clobber and error conditions
- X-seq: zsh-workers 22438
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: no_clobber and error conditions
- Date: Wed, 10 May 2006 08:59:02 -0700
- In-reply-to: <87r7324zyh.fsf@xxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <87r7324zyh.fsf@xxxxxxxxxx>
On May 9, 6:04pm, Lloyd Zusman wrote:
} Subject: File locking within zsh?
}
} Do any of you know of any functions, primitives, tricks, hacks, or even
} outright abominations which will allow me to do cooperative file locking
} from within zsh?
I was going to suggest this:
function lock {
setopt localoptions noclobber
while true
do
{
: > $1
return 0
} always {
(( TRY_BLOCK_ERROR=0 ))
} 2>/dev/null
sleep 1
done
return 1
}
However, it appears that the error from noclobber does not "throw an
exception," it merely causes the command to have exit status 1.
That's not consistent with csh behavior (tcsh in this sample):
[schaefer@toltec /tmp]$ ( set noclobber; echo > lockfile; echo oops )
lockfile: File exists.
[schaefer@toltec /tmp]$
schaefer[537] ( setopt noclobber; echo > lockfile; echo oops )
zsh: file exists: lockfile
oops
schaefer[538]
Messages sorted by:
Reverse Date,
Date,
Thread,
Author