How can I use a variable string in a regular expressions  while read line    do        if [[ line =~ *$key* ]]; then            echo line        fi    done < $filename$key is a string variable and I want to print all the lines that has the value of $key
Using a variable in a regex
bash;regular expression;bash script
You've made a few mistakes there. Here's your script corrected:while read linedo    if [[ $line =~ $key ]]; then        echo $line    fidone < $filenameThough it seems it could be replaced with a simple grep:grep $key $filename