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.
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 == *\`* ]]