Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minus sign in double quotes in grep is recognized like an option

Tags:

grep

bash

If I'm writing

grep -v "-NO" file

it says

grep: invalid option -- 'N'

So I need to write grep -v -- "-NO" file or grep -v "\-NO" file.

But why it recognizes the - as option if it is in double quotes?

like image 324
Mano Mini Avatar asked Mar 14 '23 10:03

Mano Mini


1 Answers

The quotes are removed by the shell before the arguments are passed to grep, in a step called Quote Removal. Also see Simple Command Expansion. So, really, grep never sees these quotes.

like image 88
gniourf_gniourf Avatar answered Apr 06 '23 11:04

gniourf_gniourf