Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running the following command:

cat something | egrep "(abc|def)$"

On a server running Linux.

The same OS with kernel 2.6.18 gives the correct answer, while with 2.6.19 I get:

Illegal variable name. 

Apparently the $ sign is causing the error, but the question is why is it behaving differently across kernels?

share|improve this question
Is the version of grep the same? – Lucas Kauffman Apr 29 '12 at 15:17
up vote 3 down vote accepted

1) Are you using the same type of shell on both machines?

2) Have you tried using single quotes, so that the shell doesn't try to interpret the dollar sign as a variable?

share|improve this answer

Its more likely this is an issue with the shell you're running. First, the quotes; when using single quotes, variables won't be replaced in the outcoming string. I.e.,

% VAR="hello"
% echo "$VAR world!"
hello world!
% eco '$VAR world!'
$VAR world!

In your case, its literally trying to execute $, but $ is not a valid variable name. If you use single quotes, the shell won't allow the dollar sign to be replaced.

share|improve this answer

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.