1

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?

Yon
  • 258
  • 1
  • 3
  • 8

2 Answers2

3

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?

Zee
  • 46
  • 1
1

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.

Andrew M.
  • 11,182
  • 2
  • 35
  • 29