Last active
December 18, 2015 10:09
-
-
Save kathangeorg/5766282 to your computer and use it in GitHub Desktop.
Bash: Escape Single Quotes ' #bash #escape #single quote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Strong quoting | |
Strong quoting is very easy to explain: | |
Inside a single-quoted string nothing(!!!!) is interpreted, except the single-quote that closes the quoting. | |
echo 'Your PATH is: $PATH' | |
That $PATH won't be expanded, it's interpreted as normal ordinary text, because it's surrounded by strong quotes. | |
In practise that means, to produce a text like Here's my test… as a single-quoted string, you have to leave and re-enter the single-quoting to get the character "'" as literal text: | |
# WRONG | |
echo 'Here's my test...' | |
# RIGHT | |
echo 'Here'\''s my test...' | |
# ALTERNATIVE: It's also possible to mix-and-match quotes for readability: | |
echo "Here's my test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment