Help with escape sequence for '$' symbol in EGREP function

$table is the variable which contains name of the file.
Filename may have the special character $. Need to escape $ .

Tried below options to escape dollar:

\$$table
"\$"$table""

what is the escape sequence for egrep function..?

Below is the code snippet-

my $table;
        foreach $table (split (' ',"$tables")) {
                my $table_single;
                $table_single=`ls $SourceDir/*.sql $SourceDir/*/*.sql 2>/dev/null | egrep "[0-9]\.[0-9][0-9]_$table"`;
                my $table_sql;

Hi xylus,

Unless I've misread the post;

egrep "[0-9]\.[0-9][0-9]_\$table"`;

Regards

Dave

Thanks Dave!

But $table is the variable whose value will have '$' symbol.. I want '$' symbol to be accepted for pattern matching in egrep.
As per my research, escape sequences cannot be used in egrep functions..

Looks like Perl. I don't know all the ways Perl deals with $ but I know it uses it for many things.

I also know grep interprets $ for end of line.

If the file name has a $ in it, then you will need to get that $ all the way through to grep AND have it escaped in grep so grep sees it as a data, rather than the meta character it will interpret if there is no escape character.

If you supply the escape character IN the expression to run grep, it is not being applied where needed. You will need to get the string (in the string variable) to be updated first so the escape character needed in grep is actually inside the string, in the right place (before the $).

I don't know enough Perl to tell you HOW. I can only tell you WHAT you need to do. If I were doing this in bash, I'd be running the filename string through sed to get the \ character inserted in front of every $ before inserting that string into the grep argument.