What do you understand if the Bash my_string variable contains ANY special regular expression characters, grep will cry
$ cat file crying now no cry $ var="n.*" $ echo "$var" n.* $ grep "^$var" file no cry
Now that @anubhava posed a problem for me (thank you sir), using grep for the job seems to need at least two grep , and since you want literal grep use regex characters, use -F in the last (or fgrep ):
$ cat file OMG it's full of *s $ var="*" $ grep "^.\{"${#var}"\}" file|grep -F "$var" *s
${#var} returns the length of var in Bash, and this is the number of characters we extract from the beginning of the file to check with the last grep .
(Quote from 2001 )
source share