nishit dey
nishit dey

Reputation: 458

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

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

Upvotes: 0

Views: 242

Answers (1)

anubhava
anubhava

Reputation: 785581

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

Upvotes: 4

Related Questions