I am trying to escape backtick in bash for long time. I tried escaping with \ but it does not work.
Is it possible to escape backtick in bash?
I="hello.pdf"
var1=`cat <<EOL

\`\`\`sql
some code here
\`\`\`
EOL`
echo "$var1"

```sql
some code here
```
Use $(...)
instead of backtick syntax for the outer command substitution. Thus:
I='foo.png'
var1=$(cat <<EOL

\`\`\`sql
some code here
\`\`\`
EOL
)
echo "$var1"
See this running, and emitting your desired output, at https://ideone.com/nbOrIu
Otherwise, you need more backslashes:
I='foo.png'
var1=`cat <<EOL

\\\`\\\`\\\`sql
some code here
\\\`\\\`\\\`
EOL
`
echo "$var1"
...and if you were to nest backticks inside backticks, you'd need to multiply your backslashes yet again. Just Say No to backtick-based command substitution.
By the way, something you might consider to evade this problem altogether:
I='foo.png'
fence='```'
var1=$(cat <<EOL

${fence}sql
some code here
${fence}
EOL
)
echo "$var1"
...putting the literal backticks in a variable means you no longer need any kind of escaping to prevent them from being treated as syntax.