Re: recursive grep problem [zip logs]
- From: Nix <nix-razor-pit@xxxxxxxxxxxxx>
- Date: Wed, 05 Dec 2007 00:43:12 +0000
On 2 Dec 2007, Chris Davies told this:
Nix <nix-razor-pit@xxxxxxxxxxxxx> wrote:
it's hard to change variable values in such loops because they're
executed in a subshell: you often have to have them echo variable
assignments on stdout and run the whole bloody thing in an eval $(...)).
Sounds like you and I may have written similarly complex scripts in
our time... ;-)
I wrote a data-transfer system at work which hands the actual transfer
work off to customizable and hackable shell scripts (the customization
and the decision as to which script(s) to run to get the data from
source to destination being done by the framework; it does a graph
traversal and can construct elaborate multiway tunnels on the fly and so
on: total overkill for the intended purpose, but I was hooked).
Writing something to do globbing inbound sftp transfers, or outbound
sftp transfers with overwriting banned, when sftp doesn't actually
*support* globbing... ... yeah, that took some interesting
scripting. Doubly so when you consider that
foo | while read -r FOO; do ... ; done
may hit that while loop with a SIGPIPE and terminate it when foo ends
without giving the while loop the chance to process the last up-to-
PIPE_BUF-worth of waiting data... solution, the moral equivalent of
(untested):
{ foo; echo '@@EXITING@@'; dd if=/dev/zero bs=4096 count=1; } | \
while read -r FOO; do ... ; done
where the `4096' is actually chosen by asking the C compiler for the
value of PIPE_BUF in a $(...) block, and the inside of the while loop
watches for @@EXITING@@ and does the appropriate cleanup work. I'd have
liked to just trap SIGPIPE, but ksh88/93 goes into an infinite loop if
you do that. The script also had to do different things with stdout and
stderr, was piping stuff into sftp as well as reading the output, and
the whole thing was wrapped in an eval.
(No, I couldn't just use perl's IPC::Run, which would definitely have
been simpler. No perl where this was supposed to run. Stone-age
computing, *sigh*.)
--
`The rest is a tale of post and counter-post.' --- Ian Rawlings
describes USENET
.
- References:
- Re: recursive grep problem [zip logs]
- From: Tony van der Hoff
- Re: recursive grep problem [zip logs]
- From: Nix
- Re: recursive grep problem [zip logs]
- From: Chris Davies
- Re: recursive grep problem [zip logs]
- Prev by Date: Re: DVD burner with verify option?
- Next by Date: Re: recursive grep problem [zip logs]
- Previous by thread: Re: recursive grep problem [zip logs]
- Next by thread: Re: recursive grep problem [zip logs]
- Index(es):
Relevant Pages
|