Shell Argument Escaper
Quote a string safely for bash/sh, wrapping in single quotes and handling embedded quotes.
Saída segura para shell (aspas simples):
Escaping a shell argument with single quotes
Paste the text and the page returns the safe way to pass it as a single shell argument. The technique is to wrap everything in single quotes and handle the single quote itself in a specific way: close the quoting, emit a backslash-escaped quote, and reopen. It is ugly to read and it is the correct approach.
The reason for choosing single quotes is that inside them the POSIX shell interprets nothing — not a variable, not command substitution, not even the backslash. There is no escape inside single quotes, and that absence is what makes the quoting predictable: any byte, including a newline, a dollar sign, a backtick or a semicolon, passes through literally.
The comparison with double quotes explains the rest. Inside those, dollar, backtick and backslash stay active, so text arriving from outside can execute a command. That is the difference between passing an odd filename and opening a shell injection. When the text comes from a user, a log or a database, single quotes with this escape is the pattern to follow.
Frequently asked questions
Why not backslash each special character?
Is there a byte you cannot pass?
Does this apply to PowerShell and cmd?
Related Tools
Bash PS1 Generator
Compose PS1 with ANSI colors, user, host, pwd, git branch and last exit code. Live prompt preview.
JavaScript Escape / Unescape
Escape JavaScript strings by adding backslashes before special characters and convert back to the original.
XML Escape / Unescape
Escape special XML characters (<, >, &, ", ') to entities and convert XML entities back to text.
Minimal .zshrc Generator
Build a lean .zshrc without Oh My Zsh: history, completion, simple prompt with git branch and PATH.
Bash/Zsh Aliases Generator
Predefined list of useful aliases (ll, la, gs, gd, gco, mkcd, ip) ready to paste into .bashrc or .zshrc.
HTML Escape / Unescape
Escape special HTML characters (<, >, &, ", ') to HTML entities and convert entities back to text.