Consider the following:
echo "hello" > file.txt
is_match1 () {
local m
m=$(cat "file.txt" | grep -F "$1")
if [ -z "$m" ]; then
return 1
fi
}
is_match2 () {
local m
m=$(cat "file.txt" | grep -F "$1")
test -z "$m" && return 1
}
is_match1 "hello"
echo "$?"
0
is_match2 "hello"
echo "$?"
1
Why does is_match2
return 1?