My colleague @james-masson found an interesting problem when set -o pipefail is combined with grep -q and the input to grep is produced in small chunks (like reasonably short line at a time). This combination leads to race condition when process producing input to grep may or may not receive SIGPIPE and therefore may or may not produce non 0 exit code.
#!/bin/bash
set -e
set -o pipefail
while true
do
ip route | grep -q "."
echo "done"
done
it would be awesome if shellcheck warned about it, because in general case combination of pipefail and grep -q can not produce consistent results
My colleague @james-masson found an interesting problem when
set -o pipefailis combined withgrep -qand the input to grep is produced in small chunks (like reasonably short line at a time). This combination leads to race condition when process producing input togrepmay or may not receive SIGPIPE and therefore may or may not produce non 0 exit code.it would be awesome if shellcheck warned about it, because in general case combination of
pipefailandgrep -qcan not produce consistent results