1

I don't understan why grep doesn't work in the first example

bla@ble:~/html/example$ grep -r "protected $disallowedBlockNames = array('install/end');" app/
bla@ble:~/html/example$

But

bla@ble:~/html/example$ grep -r 'protected $disallowedBlockNames = array' app/

app/Resource/Block.php:    protected $disallowedBlockNames = array('install/end');
3

You didn't provide sample input but in your first example your double quotes are allowing the disallowedBlockNames variable to be expanded by your shell before it is used by grep. I'm assuming this is a variable set in your php code and does not exist in your shell and therefore it is expanding to nothing. So what you are really sending to grep is:

grep -r "protected  = array('install/end');" app/

In the second example the single quotes prevent the shell from expanding the variable.

  • And grep -re doesn't work either? is there a way to put a $ and still have grep working – ooootramas May 11 '18 at 14:04
  • Unless you are intending to perform parameter expansion with the $ you must escape it either with single quotes or with the \ escape character. – Jesse_b May 11 '18 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.