Bash Escape Single Quote

Bash escape single quotes

In this tutorial, we will see how to escape single quote in Bash. There are multiple ways to escape single quote in Bash. Let’s go through them.

Using Double Quotes

Use double quotes to escape single quote in Bash.

echo "I'm escaping a single quote. Again, I'm doing it."
I'm escaping a single quote. Again, I'm doing it.

Using Backslash Character

Use a backslash character (\) to escape a single quote in Bash. We use this approach if the string is enclosed within the single quotes.

echo 'I'\''m escaping a single quote. Again, I'\''m doing it.'
I'm escaping a single quote. Again, I'm doing it.

The \' must be wrapped with single quotes in the above example.

Using $'...' Syntax

Use the $'...' syntax to escape a single quote in Bash. Inside the $'...', the backslash character is used to escape the single quote.

echo $'I\'m escaping a single quote. Again, I\'m doing it.'
I'm escaping a single quote. Again, I'm doing it.

That’s all about Bash escape single quote.

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.