[Top][All Lists]

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

[Help-bash] prepend to stdin

From: Brett Kail
Subject: [Help-bash] prepend to stdin
Date: Tue, 22 Dec 2015 14:18:25 -0600

I'm writing a bash script, and I would like to execute a command passing as
stdin the contents of a file followed by the script's stdin.  The command
might or might not read stdin, but regardless, I would like the entire
pipeline to end when the final command exits.  I tried this pipeline (using
false as an example command):

cat file - | true

...but it seems that something waits for a line of input before the
pipeline somehow ends without error.  What is causing this wait?  Is there
some way to disable the wait and have the entire pipeline end immediately
when the final command exits?

I was able to get the effect I want using process substitution:

true <(cat file -)

I suppose in this case, the shell kills the cat process when the final
process exits(?), which is why this gives the effect I want.  Is process
substitution the best approach, or are there downsides to be aware of?  Are
there other approaches to get the effect I want?

reply via email to

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