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


But when I use the following command

env | grep xyz*!

As expected I don't get the output as


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

1 Answer 1


* 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*!'
  • 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, 2012 at 13:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .