Skip to content

Instantly share code, notes, and snippets.

@kathangeorg
Last active December 18, 2015 10:09
Show Gist options
  • Save kathangeorg/5766282 to your computer and use it in GitHub Desktop.
Save kathangeorg/5766282 to your computer and use it in GitHub Desktop.
Bash: Escape Single Quotes ' #bash #escape #single quote
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