I'm trying to figure out how to wait for a command to complete, and then pipe stdin to stdout. I'm on a mac, but I think my question is more about how to wait for a process to complete and pipe the output then anything to do with a mac.
I've noticed that on the mac, I can run a few
say commands together, and they wait for each phrase to be fully spoken before starting the next one, if I use the
&& operator to join them up.
$ say "stage 1" && say "stage 2"
Here's where the real use case is - I've got a bash script that I'd like to have it just pass stdin to stdout, after it finishes saying something.
$ cat /etc/passwd | say_and_pass "stage 1" | grep -v test | say_and_pass "stage 2"
So conceptually, this would say aloud, "stage 1", then immediately say "stage 2", and then dump the grepped contents of
/etc/password to stdout.
My initial crack at the
say_and_pass script is this:
#!/usr/bin/env bash OUT="$*" say "$OUT" && cat
But it doesn't seem to work ;-)
EDIT: I changed the example above to use
say_and_pass "stage2" as the final command, which is needed for my solution to work...
say_and_pass, it says both "stage 1" and "stage 2" at the same time, instantly. I'd like it to say "stage 1", then immediately say "stage 2" afterwards. The intent of this is for me to be able to put audio alerts in the middle of a series of pipes. That way I'll know when some stages have completed. This is of course for long running processes that I don't want to sit and have to watch to see if they're done. The thing is sometimes, the scripts will finish fast, and talk over top of each other.
sayblocks until it is done outputting the audio; it should not overlap itself unless you are running two instances of
saysimultaneously. That said, your I/O stream is broken in your example here, so with pipes you essentially are running two instances of 'say' near-parallel. Compare
echo "foo" 1>&2 | say "foo" | echo "bar" 1>&2 | say "bar"to
echo "foo" 1>&2 ; say "foo" ; echo "bar" 1>&2 ; say "bar".