Skip to content

Instantly share code, notes, and snippets.

@shichao-an
Created September 8, 2014 18:44
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 shichao-an/f6b5961f153f061992cc to your computer and use it in GitHub Desktop.
Save shichao-an/f6b5961f153f061992cc to your computer and use it in GitHub Desktop.
Escape string for BRE
#!/bin/sh
escape() {
local raw="$1"
local quoted=$(printf %s "$raw" | sed 's/[][()\.^$?*+]/\\&/g')
echo "$quoted"
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment