Combining pipe with exit status in bash shell script?

If you do have a shell with process substitution (bash does, posix shell is not), than.

If you do have a shell with process substitution (bash does, posix shell is not), than make > >(sed s/a/A/) && date should do the trick, except bash it does not wait for the sed (it seems zsh does, but I only tried it, not checked the doc), so the output of date can get before the last line of sed output. In plain posix shell, you can use a bit more complicated construct ((make && date >&3) | sed s/a/A/) 3>&1 The date can again run before sed has processed everything, so it's output can again come before the last line of sed output. If you want the date to only run after the sed has processed everything, your only chance is storing the make status somewhere.

Something like: (make && touch make-succeeded) | sed s/a/A/ rm make-succeeded 2>/dev/null && date abusing the fact, that if the file does not exist, rm (without -f) will exit with nonzero status and silencing it's error message with redirection. As Fredrik has mentioned though, bash does in fact have a place where it does stash the exits status, so in bash you can: make | sed s/a/A/ 0 -eq $PIPESTATUS0 && date.

Thanks! Wish I could give you a bonus point for taking into account that I'd want the date to appear after the sed output. – Gnubie Sep 9 at 12:35.

Sed s/a/A/ tmp rm tmp return $rc } The temporary file should obviously be handled in a proper way; this is bare-bones in order to focus on the issue at hand. You could probably avoid a temp file altogether if you are clever with file descriptors, but it's Friday and I need more coffee.

Turn on pipefail in the make subshell. (set -o pipefail; make 2>/dev/null | sed s/a/A/) && date.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions