4

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?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
anatoly techtonik
  • 2,514
  • 4
  • 24
  • 37

1 Answers1

10

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;'
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501