Exclamation point in Bash

Here is a script using egrep that extracts the last word in each line:

egrep -o " [a-zA-Z'-]+[,:.!';?]*$" File.txt > Results.txt

If it is placed in a file with the requisite header:

#!/bin/bash

it works perfectly.

If on the other hand, one attempts it from the command line, one gets the following error:

-bash: !': event not found

The problem is the exclamation point in the regexp.

I have tried numerous ways to get it to work from the command line and failed: using single quotes, escaping the !, etc.

Nothing works.

Now, you may ask, if it works from a file, why insist on doing it from the command line? You're right. I shouldn't. And my research indicates that this problem is particularly annoying in bash and that people simply recommend using a different shell.

But can it be solved?

Thanks in advance...

Escape the !
On my pC whith Cygwin :

$ egrep -o " [a-zA-Z'-]+[,:.!';?]*$" file.txt > result.txt
bash: !': event not found

$ egrep -o " [a-zA-Z'-]+[,:.\!';?]*$" file.txt > result.txt
$

Jean-Pierre.

Well, I had only recently started using the double quotes in the expression, and I had not yet gotten around to escaping the ! in the double quotes.

So, you are right. F�licitations et chapeau. Mille mercis.