how to automatically write curl output to a new file

末鹿安然 提交于 2021-02-08 07:43:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!