问题
I am using cURL
to retrieve stock information back to the terminal window on my Mac using the yahoo finance api.
i.e. I type:
curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'
and it prints the output (in this instance the last trade price in the command line)
It works terrific, but I would like to know how to get this output automatically written to a stock.txt file located on my desktop without any manual intervention upon the execution of the original cURL command.
Thus after I type the curl query that contains the stock ticker, I get the value written in the terminal window and the txt file.
回答1:
Try this:
curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1' > ~/Desktop/stock.txt && more ~/Desktop/stock.txt
回答2:
You could use curl ... | tee ~/Desktop/stock.txt
回答3:
There is also the -o
/--output
option:
curl -o users.json https://reqres.in/api/users
来源:https://stackoverflow.com/questions/40695642/how-to-automatically-write-curl-output-to-a-new-file