Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

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)"
like image 652
Serge Makov Avatar asked Aug 09 '17 21:08

Serge Makov


People also ask

How do you append in curl?

Use the shell's appending output redirection ( >> ) rather than curl's --output option.

How do I write a curl output to a file?

For those of you want to copy the cURL output in the clipboard instead of outputting to a file, you can use pbcopy by using the pipe | after the cURL command. Example: curl https://www.google.com/robots.txt | pbcopy . This will copy all the content from the given URL to your clipboard.

How can you append the output of a command to a file?

Append to a File using the Redirection Operator ( >> ) Redirection allows you to capture the output from a command and send it as input to another command or file. The >> redirection operator appends the output to a given file.

How do I append a file?

You can use cat with redirection to append a file to another file. You do this by using the append redirection symbol, ``>>''. To append one file to the end of another, type cat, the file you want to append, then >>, then the file you want to append to, and press <Enter>.


1 Answers

Give process substitution a try.

curl --output >(cat >> file) http://url
like image 122
John Kugelman Avatar answered Nov 16 '22 03:11

John Kugelman