Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to match a string:

* * * * * /usr/local/bin/growlnotify -t 'helloTitle' -m 'helloMessage' -n 'myApp' -sw


crontab -l | grep '^[^#].*/usr/local/bin/growlnotify.*\-n \'myApp\'.*$'

it doesn't work: nothing matched.


crontab -l | grep '^[^#].*/usr/local/bin/growlnotify.*\-n.*$'

works very good:

* * * * * /usr/local/bin/growlnotify -t 'helloTitle' -m 'helloMessage' -n 'myApp' -sw

What is the problem with \'myApp\' ?

How to escape a single quote in grep/sed?

share|improve this question
-1 you really should've used a simpler example to demonstrate your point – barlop Nov 22 '14 at 19:30

2 Answers 2

one can escape single quote with -e option and using hexadecimal representation:

echo -e '\047'
> '

or in grep using hexadecimal representation and -P option:

crontab -l | grep -P '^.*/usr/local/bin/growlnotify.*\-n \047myApp\047.*$'
> * * * * * /usr/local/bin/growlnotify -t 'helloTitle' -m 'helloMessage' -n 'myApp' -sw

ss64 as reference:

       Interpret PATTERN as a Perl regular expression.
share|improve this answer

Sorry to say, but you cannot escape single quotes inside single quotes. You'll need to use double quotes. You can prove it to yourself by doing:

echo '\'' <-- doesn't work

Your shell will expect another quote.

share|improve this answer
To clarify: "\" cannot be used to escape anything inside single quotes. This is not a grep/sed issue; this is a shell issue (bash, csh, etc…). – Scott May 20 '13 at 22:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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