14,958
edits
mNo edit summary |
|||
| Line 273: | Line 273: | ||
dquote> | dquote> | ||
</pre> | </pre> | ||
=== 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. | |||
=== How to Suppress the Progress Meter === | === How to Suppress the Progress Meter === | ||