Tried
$ echo \"$STRING\" | egrep \"(\\*)\"
and also
$ echo \"$STRING\" | egrep \'(\\*)\'
and countless ot
Simply escape the asterisk with a backslash:
grep "\*"
echo "$STRING" | fgrep '*'
fgrep
is used to match the special characters.
Try a character class instead
echo "$STRING" | egrep '[*]'
Use:
grep "*" file.txt
or
cat file.txt | grep "*"
Here's one way to match a literal asterisk:
$ echo "*" | grep "[*]"
*
$ echo "*" | egrep "[*]"
*
$ echo "asfd" | egrep "[*]"
$ echo "asfd" | grep "[*]"
$
Wrapping an expression in brackets usually allows you to capture a single special character easily; this will also work for a right bracket or a hyphen, for instance.
Be careful when this isn't in a bracket grouping:
$ echo "hi" | egrep "*"
hi
$ echo "hi" | grep "*"
$