Skip to content
koducathome

cURL to Bash Converter

Convert curl commands to Bash code using curl script. Paste a command and the Bash snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The Bash curl script code appears instantly.
  3. Set up: Nothing to install beyond Bash and curl, which come with macOS and most Linux distributions.
  4. Run it: Save the code as request.sh, then run bash request.sh (or chmod +x request.sh and ./request.sh). Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no curl script equivalent.

Example

GET with headers → Bash curl script

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Bash curl script
#!/usr/bin/env bash
set -euo pipefail

url='https://api.example.com/v1/users?page=2'
headers=(
  --header 'Accept: application/json'
  --header 'Authorization: Bearer YOUR_TOKEN'
)

# The last line of the output is the status code; everything before it is the response.
response=$(curl --silent \
  --show-error \
  "${headers[@]}" \
  --write-out '\n%{http_code}' \
  "$url")
status=${response##*$'\n'}
body=${response%$'\n'*}

echo "Status: $status"
echo "$body"

Common use cases

  • Turning a one-off curl command into a reusable script
  • CI jobs and cron tasks that call an API
  • Smoke tests that check a status code

Converting curl to Bash curl script

The Bash output is a ready-to-run script around curl itself: the URL, credentials, headers and body go into variables, and the script prints the HTTP status and the response separately.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent curl script code. Options that have no curl script equivalent are listed under the editors rather than silently dropped.

Limitations

  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

How does the script get the status code?

--write-out '\n%{http_code}' adds the status as the last line of curl's output; the script splits that line off from the response body.

Why set -euo pipefail?

The script stops at the first failing command or unset variable instead of carrying on with bad data. --show-error still prints curl's own error message.

Does it work with the old Bash on macOS?

Yes. The script only uses features available in Bash 3.2, which macOS still ships.

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.