Re: recursive grep problem [zip logs]



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
.



Relevant Pages

  • How to create a test suite in Expect?
    ... I need help designing a flexible test suite for automatic test of ... computer software. ... I would like to have a flexible set of test cases scripts ... driven by a main loop that can run all test cases or the ones I want. ...
    (comp.lang.tcl)
  • Re: Recommendations for Variables, and for Compilers
    ... This requires some kind of loop, with a way to get out of the loop. ... Set Output = CreateObject ... For help coding scripts for administrative tasks like this, ... a VBScript can use the InputBox function to ...
    (microsoft.public.scripting.vbscript)
  • Re: running scripts on multiple computers
    ... The example VBScript program linked on this page uses WMI to deploy patches ... computer names, then instead of saving the names to a file, loop through the ... when you want to write scripts that work against ...
    (microsoft.public.windows.server.scripting)
  • Re: How to create a test suite in Expect?
    ... creating and running automated test suites, ... I would like to have a flexible set of test cases scripts ... > driven by a main loop that can run all test cases or the ones I want. ...
    (comp.lang.tcl)