Home > Blockchain >  How to check if there is escape character (`) is present in String for Linux Bash
How to check if there is escape character (`) is present in String for Linux Bash

Time:12-10

I was wondering how to check if the string has the escape [`] character in Linux.

str="abc|`abc`"
if [[ $str == *[`]* ]]
then
    echo "Escape character is present"
fi

I am getting error while using this.

enter image description here

CodePudding user response:

You may use:

str='abc|`abc`'

[[ $str == *'`'* ]] && echo 'Escape character is present' || echo 'no'

Escape character is present

Make sure to use single quotes around ` to disallow shell expansion.

PS: You can also use escaping like:

[[ $str == *\`* ]]
  • Related