Editing
Troubleshooting of curl errors
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== How to resolve zsh Event Not Found Error === When executing a cURL command with JSON data in zsh shell, you might encounter this error message: <pre> > zsh: event not found: \ </pre> This occurs because zsh interprets the exclamation mark (!) as a history expansion character, even when it appears inside double quotes. To resolve this error, use one of these approaches: '''Method 1: Use single quotes for JSON data''' {{kbd | key=<nowiki>-d '{"message": "Hello '\''world'\'' & welcome!", "price": "$19.99"}'</nowiki>}} '''Method 2: Escape the exclamation mark''' {{kbd | key=<nowiki>-d "{\"message\": \"Hello 'world' & welcome\!\", \"price\": \"\$19.99\"}"</nowiki>}} '''Method 3: Use heredoc with stdin''' {{kbd | key=<nowiki>-d @- << 'EOF'</nowiki>}} '''Method 4: Save JSON to file and reference it''' {{kbd | key=<nowiki>-d @payload.json</nowiki>}} '''Method 5: Disable history expansion temporarily'''<ref>[https://www.reddit.com/r/bash/comments/cl54to/not_sure_why_mac_is_saying_bash_event_not_found/?show=original not sure why mac is saying `-bash: !": event not found` when I try to simply echo a string containing a "!" : r/bash]</ref> {{kbd | key=<nowiki>set +H</nowiki>}} (before the command) Example with corrected syntax: Using single quotes: <pre> curl -X POST \ -H "Content-Type: application/json" \ -d '{"message": "Hello '\''world'\'' & welcome!", "price": "$19.99"}' \ -v \ https://example.com/api/ </pre> Using heredoc (recommended for complex JSON): <pre> curl -X POST \ -H "Content-Type: application/json" \ -d @- \ -v \ https://example.com/api/ << 'EOF' { "message": "Hello 'world' & welcome!", "price": "$19.99", "special_chars": "!@#$%^&*()_+{}|:<>?[]\\;'\",./" } EOF </pre> Using external JSON file: <pre> curl -X POST \ -H "Content-Type: application/json" \ -d @payload.json \ -v \ https://example.com/api/ </pre> Note: The heredoc approach is recommended for complex JSON as it avoids all shell interpretation issues and maintains readable formatting.
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information