help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to make sure >() is finished when a command line is


From: Russell Lewis
Subject: Re: [Help-bash] How to make sure >() is finished when a command line is finished?
Date: Sun, 22 Apr 2018 12:47:21 +0000

My (hackish) solution is to pipe the first line of your script into cat:
     cmd1 > >(cmd2) | cat

Since cat won't terminate until its stdin closes, and cmd2's stdout is
hooked to that, cat doesn't terminate until cmd2 does.

Of course, this doesn't work if you redirect cmd2's stdout.

Russ

On Sat, Apr 21, 2018, 20:00 Peng Yu <address@hidden> wrote:

> In the following example, 'o: stdout' is printed after the second
> command line is called. Is there a way to make sure it is finished
> when the first command line is finished? Thanks.
>
> $  ./main.sh
> ./script.sh > >(awk -v oprefix='o: ' '{print oprefix $0; fflush(); }')
> awk -v oprefix='o: ' '{print oprefix $0; fflush(); }'
> stderr
> ./script.sh 2> >(awk -v eprefix='e: ' '{print eprefix $0 >>
> "/dev/stderr"; fflush(); }')
> awk -v eprefix='e: ' '{print eprefix $0 >> "/dev/stderr"; fflush(); }'
> o: stdout
> stdout
> e: stderr
>
> $ cat main.sh
> #!/usr/bin/env bash
> # vim: set noexpandtab tabstop=2:
>
> set -v
> ./script.sh > >(awk -v oprefix='o: ' '{print oprefix $0; fflush(); }')
> ./script.sh 2> >(awk -v eprefix='e: ' '{print eprefix $0 >>
> "/dev/stderr"; fflush(); }')
>
> --
> Regards,
> Peng
>
>


reply via email to

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