help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] prepend to stdin


From: Greg Wooledge
Subject: Re: [Help-bash] prepend to stdin
Date: Wed, 23 Dec 2015 08:11:42 -0500
User-agent: Mutt/1.4.2.3i

He forgot to Cc: the list.  Again.

On Tue, Dec 22, 2015 at 07:04:52PM -0600, Brett Kail wrote:
> On Tue, Dec 22, 2015 at 4:03 PM, Greg Wooledge <address@hidden> wrote:
> 
> > > I better understand now how pipelines work, so I appreciate the
> > > answer won't help with my broader question since at least one character
> > > will need to be read/written in order for SIGPIPE to terminate the cat
> > > process, but I'm still curious.
> >
> > Huh?  What are you talking about?
> >
> 
> I was asking if there was some command to remove line buffering from the
> terminal.  Above, I meant that it doesn't matter if there is because cat
> would still wait for at least one character of input, so the terminal will
> appear to "hang" in any case.
> 
> 
> > Show the script, and how it is actually being used.
> >
> 
> Here's my terminal session:
> 
> $ cat pre
> pre
> $ cat a.sh
> cat pre - | ./b.sh 0 "$@"
> $ cat b.sh
> for i in "$@"; do read line; echo "$i: $line"; done; echo end
> $ ./a.sh
> 0: pre
> end
> 
> $ ./a.sh 1
> 0: pre
> line1
> 1: line1
> end
> 
> $
> 
> The empty lines and "line1" are the "echo" of me typing in the terminal.
> a.sh is the script I'm trying to write that wraps another command, which is
> simulated by b.sh.  I don't control the other command, but it reads input
> in ways my wrapper script cannot predict (I simulate that unpredictability
> using cmdline arguments).  For stdin to the other command, I want a file
> controlled by a.sh followed by the rest of the a.sh stdin passed to the
> other command.  The a.sh script above works, but there is a "hang" at the
> end while cat waits for a final line of input before trying (and failing)
> to write to the pipe that is closed because b.sh has already exited.
> 
> The following script seems to fix the problem, but I'm new to process
> substitution so I was asking if someone knew of caveats or perhaps some
> entirely different solution I hadn't considered (e.g., perhaps some way of
> terminating the processes in the pipeline if the final command exits).
> 
> $ cat a2.sh
> ./b.sh 0 "$@" < <(cat pre -)
> $ ./a2.sh
> 0: pre
> end
> $ ./a2.sh 1
> 0: pre
> line1
> 1: line1
> end
> $



reply via email to

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