![]() ![]() Mind the case of three and four slashes inside double quotes. Tt -e "def\\\\|aaa" #We send four slashes but function displays TWO Tt -e "def\\\|aaa" #We send three slashes but function displays TWO Tt -e "def\\|aaa" #We send two slashes but function displays ONE Tt -e 'def\\\\|aaa' #We send four slashes - function gets four slashes Tt -e 'def\\\|aaa' #We send three slashes - function gets three slashes See this bash function test results that prove different interpretation of single vs double quotes in args: function tt Should have something to do with bash expansion. $ cat -n file1 |grep -e 'def\\\\|zzz' #No resultsĬonclusion : For regex in grep use single quotes.īut to be honest, i don't know why the behavior is completelly different when using double quotes. $ cat -n file1 |grep -e 'def\\|zzz' #No results $ cat -n file1 |grep -e 'def|zzz' #No results Making some similar tests with single quotes we have a different and correct behavior: $ cat file1 As a consequence, the only difference between grep and grep -E for GNU grep is what has to be escaped functionality is identical.Īccording to grep man pages, and especially according to info pages, all examples given for grep include single quotes and not double quotes. In general, it's prudent to single quote your regular expression so the shell leaves it alone.Īs a side note, I don't think your C program is representative of how the shell processes arguments in Shell Operation, quoting is a separate step and includes backslash processing (see Escape Character).ġAs an extension, GNU grep allows you to escape | in BRE and get alternation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |