14

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)"

2 Answers 2

18

Give process substitution a try.

curl --output >(cat >> file) http://url
Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.