3

I have this command where I want to filter make output:

cd /app && make && sudo nginx -g 'daemon off;'

What is the correct way to insert make | pv -q -L 100 here?

9

The problem is that you'll be checking the exit status of pv. With POSIX sh syntax, you could do:

cd /app && ((make 3>&- && exec sudo nginx -g 'daemon off;' >&3 3>&-) | pv -qL 100) 3>&1

Or with ksh/bash/zsh:

(set -o pipefail
cd /app && make | pv -qL 100 && sudo nginx -g 'daemon off;')

Or with zsh:

cd /app && make | pv -qL 100 && ((!pipestatus[1])) && sudo nginx -g 'daemon off;'

Or with bash:

cd /app && make | pv -qL 100 && ((!PIPESTATUS[0])) && sudo nginx -g 'daemon off;'
  • OMG. I knew the answer won't be easy. =) – anatoly techtonik Feb 26 '15 at 12:18
  • Gives me [STDERR] /bin/sh: 1: !PIPESTATUS[0]: not found. I run this command with CMD from Dockerfile. – anatoly techtonik Feb 26 '15 at 12:47
  • 2
    @techtonik, as I said, PIPESTATUS is for bash. For sh, use the first one. – Stéphane Chazelas Feb 26 '15 at 12:54
  • Ended up with CMD bash -c "(set -o pipefail; cd /app && make | pv -q -L 150 && sudo nginx -g 'daemon off;')" – anatoly techtonik Feb 26 '15 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.