Table of Contents
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.
1 2 3 |
echo "I'm escaping a single quote. Again, I'm doing it." |
1 2 3 |
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.
1 2 3 |
echo 'I'\''m escaping a single quote. Again, I'\''m doing it.' |
1 2 3 |
I'm escaping a single quote. Again, I'm doing it. |
The \'
must be wrapped with single quotes in the above example.
Further reading:
Using $'...'
Syntax
Use the $'...'
syntax to escape a single quote in Bash. Inside the $'...'
, the backslash character is used to escape the single quote.
1 2 3 |
echo $'I\'m escaping a single quote. Again, I\'m doing it.' |
1 2 3 |
I'm escaping a single quote. Again, I'm doing it. |
That’s all about Bash escape single quote.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.