For -q option, as man grep says: Exit immediately with zero status if
any match is found, even if an error was detected.
So when matching, the read side of pipe is closed by "grep -q", while
the write side still try to write more data, which cause SIGPIPE to the
process, and the shell can not exit with 0.
Signed-off-by: Pingfan Liu <piliu(a)redhat.com>
---
dracut-module-setup.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 1f96bb8..476e274 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -92,7 +92,7 @@ kdump_setup_dns() {
_dns=$(echo $_nameserver | cut -d' ' -f2)
[ -z "$_dns" ] && continue
- if [ ! -f $_dnsfile ] || [ ! $(cat $_dnsfile | grep -q $_dns) ]; then
+ if [ ! -f $_dnsfile ] || [ ! $((cat $_dnsfile | grep $_dns) &> /dev/null)
]; then
echo "nameserver=$_dns" >> "$_dnsfile"
fi
done < "/etc/resolv.conf"
@@ -319,7 +319,7 @@ kdump_setup_netdev() {
get_ip_route_field()
{
- if `echo $1 | grep -q $2`; then
+ if [ ! $((echo $1 | grep $2) &> /dev/null) ]; then
echo ${1##*$2} | cut -d ' ' -f1
fi
}
--
2.7.4