Grep with quotation mark

I am trying to check the error log for lines with 503 errors, so I am ready for " 503 (quote from space 503).

It seems simple, but it will not work:

 grep '" 503 ' access.log 

I get the following error:

bash: -c: line 0: unexpected EOF while looking for a match `` '' bash: -c: line 1: syntax error: unexpected end of file

+6
source share
4 answers

The problem arose due to some erroneous directives in .bashrc .

0
source

It looks like you are using it through some system () in some language, right? Try:

 grep '\" 503 ' access.log 

or

 grep "\" 503 " access.log 

Directly in the shell, just grep '" 503 ' access.log will work. To reproduce your problem, I have to do:

 bash -c 'grep '\" 503 ' access.log' 

This is really a syntax error. To do this work, I need:

 bash -c 'grep "\" 503 " access.log' 

You somehow call bash -c ... Maybe indirectly. You need to find out what it's called to find out which quotes are in conflict.

+8
source

To debug such strange effects, use "set -x" to display shell extensions and what the computer thinks of your command.

+1
source

I believe that I am working now (not sure, because I did not get any results, but did not get an error).

The reason is because I am passing it using the ssh command as shown below and I believe that SSH does some trickery tricks:

 ssh 123.123.123.123 grep '" 503 ' access.log 

A modification to this is the fix:

 ssh 123.123.123.123 "grep '\" 503 ' access.log" 

Thanks for all the time.

0
source

Source: https://habr.com/ru/post/894315/


All Articles