bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] gawk - 'inplace' feature ignores file's access flags (rea


From: Andrew J. Schorr
Subject: Re: [bug-gawk] gawk - 'inplace' feature ignores file's access flags (read-only)
Date: Tue, 16 Jun 2015 14:54:08 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, Jun 16, 2015 at 12:37:05PM -0600, Bob Proulx wrote:
> For example without -i one needs all of this infrastructure:
> 
> #!/bin/sh
> unset tmpfile
> cleanup() { test -n "$tmpfile" && rm -f "$tmpfile" ;}
> trap "cleanup" EXIT
> trap "cleanup; trap - HUP; kill -HUP $$" HUP
> trap "cleanup; trap - INT; kill -INT $$" INT
> trap "cleanup; trap - QUIT; kill -QUIT $$" QUIT
> trap "cleanup; trap - TERM; kill -TERM $$" TERM
> trap "trap - PIPE; cleanup; kill -PIPE $$" PIPE
> tmpfile=$(mktemp ./foo.XXXXXXXX) || exit 1
> echo "foo" > "$tmpfile" || exit 1
> mv "$tmpfile" foo || exit 1
> exit 0
> 
> Having -i can save a lot of possibility for errors.

These are good points, but I don't think the gawk inplace feature
actually traps signals.  So your script is better. :-)

bash-4.2$ echo hello > test
bash-4.2$ echo junk >> test
bash-4.2$ gawk -l select -i inplace '{print $0, "more stuff"; 
kill(PROCINFO["pid"], "term")}' test
Terminated
bash-4.2$ ls -l
total 8
-rw-r--r-- 1 schorr ead 11 Jun 16 14:50 test
-rw-r--r-- 1 schorr ead 17 Jun 16 14:50 test.gawk.J5rOK8
bash-4.2$ head *
==> test <==
hello
junk

==> test.gawk.J5rOK8 <==
hello more stuff

Do sed and perl trap signals properly?

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]