facebook/zstd

zstdgrep parsing of grep options naively broken

Open

#2,064 创建于 2020年4月3日

在 GitHub 查看
 (6 评论) (5 反应) (0 负责人)C (27,100 star) (2,481 fork)batch import
bughelp wantedlong-term

描述

Describe the bug zstdgrep as a wrapper for zstdcat | grep should handle grep options properly. It doesn't in several cases. A few examples below.

To Reproduce

# The fact that the -e grep option can be specified multiple times
# for multiple pattern is not handled at all, nor is the use of equivalent
# long options with or without = between them and their arguments

$ echo start > /tmp/file
$ echo stop >> /tmp/file
$ grep -e start -e stop /tmp/file
start
stop
$ grep --regexp=start --regexp=stop /tmp/file
start
stop
$ grep --regexp start --regexp stop /tmp/file
start
stop
$ grep --regexp start --regexp stop -e start /tmp/file
start
stop
$ grep --regexp start --regexp=stop -e start /tmp/file
start
stop
$ zstdgrep --regexp=start --regexp=stop /tmp/file
/tmp/file:start
/tmp/file:stop
Incorrect parameters
$ zstdgrep --regexp start --regexp stop /tmp/file
zstd: can't stat --regexp : No such file or directory -- ignored 
grep: start: No such file or directory
zstd: can't stat stop : No such file or directory -- ignored 
grep: start: No such file or directory
grep: start: No such file or directory
$ zstdgrep -e start -e stop /tmp/file
zstd: can't stat -e : No such file or directory -- ignored 
zstd: can't stat stop : No such file or directory -- ignored 
/tmp/file:start

# --file= and -f with different behaviours for
# -, /dev/fd/0, /dev/stdin as pattern files 
# also regarding when to print the name of the examined file

$ echo start | grep -f - /tmp/file
start
$ echo start | zstdgrep -f - /tmp/file
$ echo start | grep --file=- /tmp/file
start
$ echo start | zstdgrep --file=- /tmp/file
/tmp/file:start

# --file= and -f with different behaviours
# Process substitutions with bash not working as with grep on its own

$ cp  /tmp/file /tmp/file2
$ grep --file=<( echo start ) /tmp/file /tmp/file2
/tmp/file:start
/tmp/file2:start
$ grep -f <( echo start ) /tmp/file /tmp/file2
/tmp/file:start
/tmp/file2:start
$ zstdgrep --file=<( echo start ) /tmp/file /tmp/file2
/tmp/file:start
/tmp/file2:start
$ zstdgrep -f <( echo start ) /tmp/file /tmp/file2
/tmp/file:start

Expected behavior For the behavious of the wrapper to mimic precisely what grep would do on its own.

Additional context Zstd version 1.4.4

贡献者指南

zstdgrep parsing of grep options naively broken · facebook/zstd#2064 | Good First Issue