Serge Makov
Serge Makov

Reputation: 173

curl --output append to a file (without >> redirection)

Is there a way for curl to append output to an existing file using --output/-o option without overwriting it? I cannot use redirection:

curl http://url >> file

Because I am using a return code from curl:

response="$(curl --write-out "%{http_code}" --silent --output file http://url)"

Upvotes: 14

Views: 4178

Answers (2)

John Kugelman
John Kugelman

Reputation: 361547

Give process substitution a try.

curl --output >(cat >> file) http://url

Upvotes: 18

glenn jackman
glenn jackman

Reputation: 246744

It appears not. You can write to a temp file and then append to your actual output file:

tmp=$(mktemp)
trap "rm $tmp" EXIT

response=$(curl --output "$tmp" ...)

cat "$tmp" >> output.file

Upvotes: 3

Related Questions