← All Tools

When the cURL Generator Breaks Silently — Shell Escaping Asymmetry

Guide · Last verified Aug 26, 2026

If you've ever typed a header value into the cURL Generator, copied the resulting command, pasted it into a terminal, and gotten a mysterious syntax error — the cause is likely not a bug in the tool but the quoting rules of the shell itself (bash and friends). This guide breaks down, at the code level, why the single quote (') gets special treatment in the shell, and why that structurally forces any tool that auto-generates cURL commands to behave differently depending on which field you're filling in.

1. Why Even a Backslash Means Nothing Inside Single Quotes

In bash and other POSIX-style shells, a string wrapped in single quotes is treated as "fully literal." Wrap it in double quotes (") instead, and backslash escapes still work for a handful of characters like \", \\, and \$ — but inside single quotes, there are no exceptions at all. Even a backslash is treated as a plain literal character. As a result, there is no way, within shell syntax itself, to put a single quote inside a single-quoted string — there's no mechanism to "escape and ignore" the very character that started the quoting in the first place.

2. Which Is Why the `'...'\''...'` Trick Exists

The only way around this limitation is to split the quoted section into pieces. To safely pass the string It's broken to the shell, you write 'It'\''s broken'. This is a concatenation of three pieces: ① 'It' — the literal "It" in single quotes, ② \' — a single quote character, escaped with a backslash outside of any quoting, ③ 's broken' — the literal "s broken," again in single quotes. Because the shell joins adjacent tokens with no space between them, the final result is the single word "It's broken." Any tool that programmatically inserts user input into a shell command needs to apply this transformation automatically to be safe.

3. The cURL Generator's Actual Code: Body Is Safe, Everything Else Is Not

A direct inspection of modoohub's cURL Generator code shows that this transformation is not applied consistently. The part that assembles the request body (-d) correctly applies exactly the three-step trick above, via body.replace(/'/g,"'\\''"). The parts that assemble header values, the Bearer token, and the URL, however, only wrap the value in single quotes as -H 'header-name: header-value' — they never escape single quotes appearing inside that value. In other words, within the very same command, the safety level differs depending on which field you're looking at: an asymmetric structure. This isn't unique to this tool — it's a common implementation pattern where only the body gets escaping attention while headers get waved off with "the values are short, it'll probably be fine."

4. A Real-World Example: An Apostrophe in a Header Value

Say you enter It's broken as a custom header value. The generator produces the following command.

StageContent
Header value you enteredX-Note: It's broken
Generated command fragment-H 'X-Note: It's broken'
How the shell actually reads it'X-Note: It' (literal) + s (a word joined with no space) → the argument value is transformed into "X-Note: Its", and then the shell hits the unclosed single quote in broken' and either throws a syntax error or hangs waiting for input

In an interactive terminal, the prompt switches to > and waits indefinitely for a closing single quote to appear. Run as a script, it ends with an error like unexpected EOF while looking for matching \`''. A single common apostrophe in a short value is enough to make the entire command behave nothing like what you intended.

5. When It's Safe, and When You Need to Fix It Yourself

Frequently Asked Questions

Q. Why is the cURL Generator's body (-d) field safe?

Because the code processes the body value with body.replace(/'/g,"'\\''"), automatically converting every single quote in the value into the three-step form the shell can read safely. This processing is not applied to the header, URL, or Bearer token fields.

Q. Wouldn't wrapping the value in double quotes (") solve this?

It would solve the apostrophe problem, but it introduces new ones: inside double quotes, $ (variable expansion), ` (command substitution), and \ (escaping) all get special treatment. If any of these characters end up in the value, there's a risk they get unintentionally interpreted as a shell command or variable — so it's not a fundamental fix.

Q. Does the same problem happen in Windows PowerShell?

PowerShell's quoting rules differ from bash's (it escapes a single quote inside single-quoted text by writing two single quotes in a row). This guide is based on bash/zsh, the default shells on macOS/Linux — pasting a command generated here directly into PowerShell may break in a different way.

Q. What's the simplest way to avoid this problem?

If there's any chance a header value or URL might contain a single quote, don't run the generator's output as-is — manually fix just that value using the '\'' pattern before running it. Alternatively, you can use the Regex Generator to check ahead of time whether a value contains an apostrophe.