Escape / Unescape
Shell Escape — Quote a String for Bash, sh, zsh and PowerShell
Wrap a string the way a POSIX shell or PowerShell actually needs it quoted — including the output's own quotes, ready to paste into a command line.
In short
Escape a string for the shell online: POSIX single-quote wrapping, double-quote escaping or backslash style for bash, sh and zsh, plus PowerShell single quotes. Free.
By NaveenKumar T · Updated
- Escape & unescape in one tool
- Handles every special character
- Instant as you switch modes
Runs entirely in your browser — nothing you paste or open here is uploaded, logged, or stored.How we handle data →
Example
Shell Escape: input and output
A filename containing an apostrophe, spaces, a variable-looking dollar sign, an ampersand and an exclamation mark — the kind of value that breaks an unquoted command instantly.
Ada's report (final) $HOME/new & old.txt'Ada'\''s report (final) $HOME/new & old.txt'The whole value is wrapped in single quotes with one splice at the apostrophe — '\'' — while the space, the $, the & and the parentheses need nothing extra, because single-quote style treats them as ordinary literal characters too.
Learn more
Shell escaping rules
POSIX shells (bash, sh, zsh, dash) give single quotes one job and no exceptions: everything between a pair of ' characters is completely literal — no variable expansion, no command substitution, not even a backslash means anything special. That makes single-quote wrapping the only fully reliable way to quote an arbitrary string, with one wrinkle: since nothing inside single quotes is special, there is no way to place a literal single quote inside them, so the standard idiom closes the quote, inserts an escaped quote outside it, and reopens — the four-character sequence '\'' — which this tool applies automatically when the value contains one.
Double quotes trade some of that safety for convenience: text stays mostly literal, but $variable, `command` and \ still do their normal jobs, so those three characters (plus the closing " itself) need a backslash if you want them literal. Backslash style skips quoting altogether and escapes every individual character a shell would otherwise treat specially — useful for a short value with no whitespace problems, but it cannot represent a literal newline at all, since there is no backslash sequence for one outside of a $'...' ANSI-C-quoted string. Unlike the language escape tools on this site, the output here is a complete shell WORD, quotes included — you paste it straight into a command line rather than splicing it between quote characters you supply yourself.
Three ways to quote in POSIX shells
Pick the narrowest style that still does the job: single quotes when nothing inside should be interpreted at all, double quotes when part of the value legitimately needs shell expansion, backslash style only for short values you know contain no newlines.
| Style | What stays literal | What still expands | Use it for |
|---|---|---|---|
| Single quote '…' | Everything, including \, $ and ` | Nothing | Any value — the safe default |
| Double quote "…" | Most characters | $variable, `command`, \-escaped chars | A value that must still carry a live variable or substitution |
| Backslash a\ b | Each escaped character | Anything not preceded by a backslash | Short values with no newlines and no quoting preference |
The same job in your language
Most languages that shell out to a subprocess ship a quoting helper — reach for it instead of hand-rolling escapes in application code; this tool is for the times you're building a command by hand.
| Language / tool | Function |
|---|---|
| Shell itself | printf '%q' "$value" |
| Python | shlex.quote(value) |
| Node.js | the shell-quote or shell-escape package |
| Ruby | Shellwords.escape(value) |
| PHP | escapeshellarg(value) |
| PowerShell | value -replace "'", "''" (then wrap in single quotes) |
Help
Frequently asked questions
Everything you need to know about the Shell Escape.
01How do I escape or unescape Shell here?
Pick a style — single-quote (the safe default for anything with spaces or shell metacharacters), double-quote (when the shell still needs to expand something else nearby), backslash (no quotes, character-by-character), or PowerShell — paste the value, and press Escape. Copy the result straight into your command line; it already includes its own quoting.
02Why wrap everything in single quotes instead of escaping each character?
Because POSIX shells give single quotes exactly one meaning — pure literal text — with zero exceptions, while backslash-escaping has to correctly enumerate every character that's special across every context a word might appear in (globbing, word splitting, history expansion in interactive shells, and more). Get one character out of that list and the escaped-but-unquoted version breaks in a way that's easy to miss in testing and dangerous in production; a wrongly-quoted value is one of the most common sources of shell-injection bugs in scripts that build commands from variables. Single-quote wrapping needs exactly one special case — an embedded single quote — which is why it's this tool's default style.
03How do I escape a single quote inside single quotes in bash?
You can't put one inside the quotes — nothing can escape inside a single-quoted string, single quotes included — so the standard trick closes the string, contributes the quote a different way, and reopens the string: 'Ada'\''s report' means "the literal text Ada", then \' outside any quoting (a backslash-escaped single quote, valid in an unquoted shell word), then 's report' as another literal string — and the shell concatenates all three adjacent words into a single argument Ada's report. This tool builds that sequence automatically: every ' in your input becomes '\'' and the whole value is wrapped in an outer pair of quotes. The alternative some scripts use is bash's $'...' ANSI-C quoting, where \' does mean an escaped quote directly, but that syntax is a bash/zsh/ksh extension, not POSIX sh — the '\'' idiom this tool produces works absolutely everywhere.
04When do I need double quotes — variables and command substitution?
Whenever the shell should still DO something with part of the value even though most of it is literal text — expand $HOME inside a path, run `date` and splice in its output, or preserve a variable's word-splitting behavior differently from single quotes. Double-quote style here backslash-escapes only the four characters that remain special inside double quotes — " \ $ and the backtick — so $HOME stays as the literal text $HOME in the output rather than the two characters $ and H-O-M-E becoming something a live shell would later expand; that's correct if you intend to paste the result somewhere it should stay inert, and it is exactly the escaping printf '%q' and most "quote for double quotes" library functions perform.
05Does this work for zsh, dash, fish, PowerShell and cmd.exe?
The single-quote, double-quote and backslash styles follow POSIX.1-2024's Shell Command Language, which bash, sh, dash and zsh (in its default, non-csh-emulation mode) all implement identically for quoting purposes — so those three styles are safe for any of them. fish is the outlier among Unix-like shells: it accepts single-quote wrapping for the same literal effect, but its OWN escape for an embedded quote inside single quotes is a bare backslash before the quote (\') rather than the '\'' idiom, so fish-specific scripts should use fish's own string escape rather than this tool's single-quote output. The PowerShell style here handles PowerShell's single-quoted strings (doubling an embedded ' is PowerShell's equivalent trick). cmd.exe is intentionally out of scope: its quoting rules depend on which built-in or program is parsing the arguments and have no single consistent standard, so there is no one correct escaping to generate.
06Why isn't ! escaped in double-quote style?
Because in a plain POSIX sh double-quoted string, ! is not special — it is bash and zsh's interactive-mode history expansion (the feature that turns !! into your last command) that gives it meaning, and that expansion is normally disabled in scripts and non-interactive shells, and it happens on the raw command line before quoting is even parsed, not inside every double-quoted string. Escaping it here would produce a backslash that isn't part of POSIX double-quote grammar at all — bash would print a literal backslash followed by an unescaped !, doing more harm than leaving it alone. If you specifically need to defeat interactive history expansion, run set +H first or use single-quote style, which truly is unconditional.
Keep working
Related tools
SQL Escape
Escape / Unescape
URL Encode / Decode
Percent-encoding both ways — make any text safe in a URL, or turn %20-soup back into readable text.
CSV Escape
Escape / Unescape
Cron Expression Generator
Five dropdowns in, plain English out — with the next ten run times in your local timezone so you ship the schedule you actually meant.
JSON Escape
Escape / Unescape
Python Escape
Escape / Unescape