protect a pattern beginning
with a hyphen (-)
echo -e "-n\n-i\n-e" | grep -Pe '-(n|i|e)'
echo -e "-n\n-i\n-e" | grep -P -- '-(n|i|e)'
man bash
-- A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.
echo -e "-e\n-i\n-n" | grep -P -- -n '-(e|i|n)'
grep: -(i|n|e): 没有那个文件或目录
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |