Shell Argument Escaper

Quote and escape strings for safe Bash/sh command arguments

Ad placeholder (leaderboard)

Passing untrusted text to a shell is dangerous: spaces split it into multiple arguments and characters like ;, |, and backtick can run commands. This tool wraps a value into one inert, shell-safe argument using POSIX single-quoting.

How it works

The whole value is wrapped in single quotes, inside which every character is literal. The only character that cannot appear inside single quotes is the single quote itself, so each one is rewritten as the four-character sequence '\'':

hello world   -> 'hello world'
O'Brien       -> 'O'\''Brien'
rm -rf /; ls  -> 'rm -rf /; ls'   (semicolon is now literal)
(empty)       -> ''               (one empty argument)

The shell concatenates adjacent quoted and escaped pieces back into the exact original string, while never interpreting any of its characters as syntax.

Tips and notes

Single quotes beat double quotes for safety because double quotes still expand $, backtick, and \. The '\'' idiom looks odd but is the canonical, portable way to embed a quote — it works in sh, Bash, Zsh, and Dash alike. Always quote the empty string as '' so it survives word-splitting as a real empty argument. Use this whenever you build a command line from variable data; for larger scripts, prefer arrays or passing data via environment or stdin instead.

Ad placeholder (rectangle)