0

For example:

man perl | grep '-w'

only to receive error messages

2
  • man perl | grep -- '-w' Commented Jun 26, 2017 at 7:02
  • man perl | grep -F "-w" Commented Mar 28, 2020 at 15:54

3 Answers 3

4

Use the double hyphen:

% man perl | grep -- '-w' The "use warnings" pragma produces some lovely diagnostics. One can also use the -w flag, but its use is normally discouraged, because it gets applied to all executed Perl code, 

This usage of -- is recommended by the POSIX standard:

The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the - character.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much
Could you provide some references about the usage of '--'?
@MuYuanLi: added
2

or just escape - character:

man perl | grep '\-w' 

output:

 also use the -w flag, but its use is normally discouraged, because it 

Comments

1

Use -- to give a parameter which starts with - .

MacBook-Pro:~ chen$ man perl | grep -- '-w' also use the -w flag, but its use is normally discouraged, because it MacBook-Pro:~ chen$ 

In most bash builtin & some other commands, the -- means the end of options. By the same token, you can delete a file which name is -f.txt using this command:

MacBook-Pro:tmp chen$ rm -fv -- -f.txt -f.txt MacBook-Pro:tmp chen$ 

2 Comments

Thanks, could you provide some refferences on when and how to use '--'?
man getopt : The getopt utility will place `--' in the arguments at the end of the options, or recognize it if used explicitly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.