Vincent Gheur
Vincent Gheur

Reputation: 51

What does a dollar sign means in front of a regexp given to the grep command?

I was looking at how I could grep some non printable characters in files. I finally found this to be working:

grep -c $'\xEF\xBB\xBF' *.xml

However, I couldn't find anywhere the meaning of the initial dollar sign (and it must play a role, as the command doesn't work if you remove it...)

All my searches were of course spammed by the "How to grep for a dollar sign", "How to escape the dollar sign" and "What's the special meaning of dollar regexps"... I haven't also found anything in the grep or regexp documentation...

Does someone know what it means (and maybe what else it can be used for ?)

Thanks !

Upvotes: 2

Views: 424

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626952

The answer is in man bash:

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:

         \a     alert (bell)
         \b     backspace
         \e
         \E     an escape character
         \f     form feed
         \n     new line
         \r     carriage return
         \t     horizontal tab
         \v     vertical tab
         \\     backslash
         \'     single quote
         \"     double quote
         \nnn   the eight-bit character whose value is the octal value nnn (one to three digits)
         \xHH   the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
         \cx    a control-x character

Upvotes: 2

Related Questions