Skip to content

Instantly share code, notes, and snippets.

@terrisgit
Created January 27, 2023 16:32
Show Gist options
  • Save terrisgit/c776d468a0409959b33cf70400525de9 to your computer and use it in GitHub Desktop.
Save terrisgit/c776d468a0409959b33cf70400525de9 to your computer and use it in GitHub Desktop.
Surround a command-line argument with apostrophes and escape the apostrophes in the value
// See https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings
const zipPath = "fo''o.zip";
const escapedZipPath = zipPath.replace(/'/g, "'\\''");
const cmd = `/usr/bin/unzip '${escapedZipPath}' > /dev/null 2> /dev/null`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment