0

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.

4

* 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 '12 at 13:51

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.