Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151328273
D26616.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D26616.id.diff
View Options
Index: head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
===================================================================
--- head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
+++ head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
@@ -891,6 +891,24 @@
atf_check -o inline:"test1:2\n" grep -m 2 -EHc "a|b|e|f" test1
}
+
+atf_test_case zgrep_multiple_files
+zgrep_multiple_files_head()
+{
+ atf_set "descr" "Ensures that zgrep functions properly with multiple files"
+}
+zgrep_multiple_files_body()
+{
+ echo foo > test1
+ echo foo > test2
+ atf_check -o inline:"test1:foo\ntest2:foo\n" zgrep foo test1 test2
+
+ echo bar > test1
+ atf_check -o inline:"test2:foo\n" zgrep foo test1 test2
+
+ echo bar > test2
+ atf_check -s exit:1 zgrep foo test1 test2
+}
# End FreeBSD
atf_init_test_cases()
@@ -944,5 +962,6 @@
atf_add_test_case fgrep_oflag
atf_add_test_case cflag
atf_add_test_case mflag
+ atf_add_test_case zgrep_multiple_files
# End FreeBSD
}
Index: head/usr.bin/grep/zgrep.sh
===================================================================
--- head/usr.bin/grep/zgrep.sh
+++ head/usr.bin/grep/zgrep.sh
@@ -157,28 +157,35 @@
pattern_found=1
fi
-ret=0
# call grep ...
if [ $# -lt 1 ]
then
# ... on stdin
if [ ${pattern_file} -eq 0 ]; then
- ${cattool} ${catargs} - | ${grep} ${grep_args} -- "${pattern}" - || ret=$?
+ ${cattool} ${catargs} - | ${grep} ${grep_args} -- "${pattern}" -
else
- ${cattool} ${catargs} - | ${grep} ${grep_args} -- - || ret=$?
+ ${cattool} ${catargs} - | ${grep} ${grep_args} -- -
fi
+ ret=$?
else
# ... on all files given on the command line
if [ ${silent} -lt 1 -a $# -gt 1 ]; then
grep_args="-H ${grep_args}"
fi
+ # Succeed if any file matches. First assume no match.
+ ret=1
for file; do
if [ ${pattern_file} -eq 0 ]; then
${cattool} ${catargs} -- "${file}" |
- ${grep} --label="${file}" ${grep_args} -- "${pattern}" - || ret=$?
+ ${grep} --label="${file}" ${grep_args} -- "${pattern}" -
else
${cattool} ${catargs} -- "${file}" |
- ${grep} --label="${file}" ${grep_args} -- - || ret=$?
+ ${grep} --label="${file}" ${grep_args} -- -
+ fi
+ this_ret=$?
+ # A match (0) overrides a no-match (1). An error (>=2) overrides all.
+ if [ ${this_ret} -eq 0 -a ${ret} -eq 1 ] || [ ${this_ret} -ge 2 ]; then
+ ret=${this_ret}
fi
done
fi
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 8, 3:30 PM (17 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31105368
Default Alt Text
D26616.id.diff (2 KB)
Attached To
Mode
D26616: zgrep: fix exit status with multiple files
Attached
Detach File
Event Timeline
Log In to Comment