Skip to content

Instantly share code, notes, and snippets.

@ppenguin
Last active October 6, 2020 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppenguin/e170c64269e42dc62895ab2002021bab to your computer and use it in GitHub Desktop.
Save ppenguin/e170c64269e42dc62895ab2002021bab to your computer and use it in GitHub Desktop.
bash (portable) quote a single quote in double quotes for substitution in a single quoted field (for use in e.g. borg --exclude pattern)
# or, in other words: close single quote ' | dquote squote "'" | start single quote ', but this all quoted within single quotes for the sed command
# so this sed MUST ONLY be used for text which is substituted in a field which is itself quoted in single quotes (as in our --exclude='<pattern>')
<crazy output with string including single quote(s)> | sed -e 's/'"'"'/'"'"'"'"'"'"'"'"'/g' | awk ... -v q="'" '{ printf "--exclude="q"*/%s"q" ", $1 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment