With zsh you may do
setopt rcquotes
. Then ASCII apostrophes are escaped just like this:
echo 'Don''t'
. Or setup your keymap to be able to enter UTF apostrophes, they have no issues with any kind of quotes (including none) in any shell:
echo 'Don’t'
. Third works both for zsh and bash:
echo $'Don\'t'
.
Neither first nor third can narrow down quote to a single character, but they are still less verbose for non-lengthy strings then heredocs suggested above. With zsh you can do this by using custom accept-line widget that will replace constructs like 'Don't'
with 'Don'\''t'
. Requires rather tricky regex magic that I can write only in perl; and is probably not the best idea as I can’t pretend I can cover all possible cases before they will hit. It won’t in any case touch any scripts.