Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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

 
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.