Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a variable "abc" with value "xyz*!@#" in my unix account (ksh). I used export command to export this variable into the environment. When I use grep command as below

env |grep xyz

I get the output

abc=xyz*!@#

But when I use the following command

env | grep xyz*!

As expected I don't get the output as

abc=xyz*!@#

In fact, I don't get any output at all.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

* has special meaning in regular expressions, so escape it:

env | grep 'xyz\*!'

Or use the -F option to tell grep to treat the parameter as plain text, not as regular expression:

env | grep -F 'xyz*!'
share|improve this answer
    
When not using regex, grep -F is probably easier than trying to escape not-a-regex into a regex with normal grep. –  jw013 Nov 1 '12 at 13:51
add comment

Your Answer

 
discard

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.