Skip to content

Instantly share code, notes, and snippets.

@nottsknight
Created February 2, 2013 17:08
Show Gist options
  • Save nottsknight/4698334 to your computer and use it in GitHub Desktop.
Save nottsknight/4698334 to your computer and use it in GitHub Desktop.
BASH function to escape all ' ' characters in a string, e.g. for formatting a file name for use over scp
#!/usr/bin/env bash
function escapeSpaces () {
if [[ -n $1 ]]; then
string=`echo $1 | sed -r 's/[ ]+/\\\\\\ /g'`
echo "$string"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment